Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does the .f in 1000.f mean? c++ [duplicate]

Tags:

c++

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?

like image 640
SimplyZ Avatar asked Jun 08 '11 23:06

SimplyZ


People also ask

What does .F mean in C++?

f means float. It's like a C programming language.

Is 1.0 float or double C++?

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 .

Why do we use F in float in C++?

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 .


2 Answers

1000 is an int literal.

1000. is a double literal.

1000.f is a float literal.

like image 198
Luc Danton Avatar answered Sep 29 '22 08:09

Luc Danton


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.

like image 26
Chris Dodd Avatar answered Sep 29 '22 07:09

Chris Dodd