c++floating-pointprecisionliteralssuffix

Is there a functional difference between "2.00" and "2.00f"?


I ask because I am using the Box2D library, which calls for mostly float arguments. Although I see a lot of example code that uses the 0.00f format, I am not quite sure if there is an actual difference between that and plain old 0.00.

Will I be hurting myself later on by not appending the additional f? Is it a speed thing? Is there some sort of connotation that would need the f addend when others wouldn't?

TL;DR: Why should I be using 0.00f instead of 0.00?


Solution

  • The f suffix makes it a single precision(float) literal instead of a double precision literal. This usually means 32 bit instead of 64 bit floats.

    Floating-point constants default to type double. By using the suffixes f or l (or F or L — the suffix is not case sensitive), the constant can be specified as float or long double, respectively.

    http://msdn.microsoft.com/en-us/library/tfh6f0w2(v=VS.100).aspx