I am following a tutorial on how to make a game with SDL. At a certain point in the tutorial I need to calculate the game's FPS. The tutorial does the following:
caption << "Average Frames Per Second: " << frame / ( fps.get_ticks() / 1000.f );
Now, I know exactly what the code does, except for the part where it divides by 1000.f. I've been looking but just can't find what .f means.
So my question is, what does .f mean? And why is it there?
f means float. It's like a C programming language.
float f = 1.0; 1.0 a literal of type double while f is a float , hence the compiler does an implicit narrowing conversion to float , the same holds true for double d = 1.0f where it's widening implicit conversion from float to double .
The . f tells the compiler to interpret the literal as a floating point number of type float. There are other such constructs such as for example 0UL which means a (unsigned long)0 , whereas a plain 0 would be an (int)0 .
1000
is an int
literal.
1000.
is a double
literal.
1000.f
is a float
literal.
It means this is a float
constant rather than a double
constant. As for the effect, on most C++ compilers, it will have no effect as the float
will be converted to a double
to do the divide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With