No. Any value assigned to a float
variable will automatically be narrowed to float
regardless of the f
suffix.
Here's an example of where it makes sense to use f
or explicitly cast to float
:
float gPhase;
float gFrequency;
float gInverseSampleRate;
....
gPhase += 2.0 * M_PI * gFrequency * gInverseSampleRate;
As written above, the compiler will see that there is at least one double
term in the multiplication (2.0
and M_PI
are both double
constants) and will generate a double-precision multiplication between all the terms and then narrow down the result to float
when storing it into gPhase
. One can add a f
suffix to 2.0
and an explicit float()
cast to M_PI
so all terms are single-precision and only single-precision instructions are generated instead:
gPhase += 2.0f * (float)M_PI * gFrequency * gInverseSampleRate;