Crossing symmetry and modular invariance in conformal field theory and S duality in gauge theory