The distance to L^\infty in some function spaces and applications