Quote:Original post by avocados
I just found one of my old projects that had 0 warnings and added these two lines into the main function:
float abc = 2.0f;abc += pi;
Then I recompiled with 0 warnings. I pasted the same two lines into my current project and recompiled and got a truncation warning for the line that adds pi. From what I can tell, there really is an inconsistancy here.
You're probably using different warning levels for the two projects.
Anyway, the PI constant is still a double precision constant. But since you probably want to keep it at full precision I recommend casting it manually within the conversion instead (abc += (float) pi;).
Of course you can always disable to warning, but OTOH they've helped me track down precision issues on more than one occasion.
Quote:Original post by avocados
What about the sine functions? I've never had to add (float) in front of them before, is that standard practice?
C has special float versions of all floating point math functions (sinf, cosf, tanf, powf, etc..). In C++ they're also overloaded on the input type, so sin(3.0f) would return a float for instance.