0.0f, 0.0, 0

Started by
12 comments, last by brulle 18 years, 7 months ago
Quote:Original post by mbruenjes
If you put a 'f' behind a floating point number, the compiler uses a float than cast it from double to float (I read that once somewhere).
So float b = 0.0f should be a little faster than float b = 0.0 or float b = 0;

I seriously doubt any compilers worth using would do those conversions at run time. Speed is not an issue when dealing with literals.

CM
Advertisement
#include <iostream>void foo(int)    { std::cout << "it's an int."   << std::endl; }void foo(float)  { std::cout << "it's a float."  << std::endl; }void foo(double) { std::cout << "it's a double." << std::endl; }int main(){   foo(0);   foo(0.0f);   foo(0.0);}
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Quote:Original post by Glak
"and am actually wondering if this is just for the sake of clarity?"

clarity is THE key to good programming.


Agreed. Always EXPLICITLY code what you mean. Don't let the compiler try to figure out what you meant. Besides, I hate sifting through other people's code when they shortcut it by leaving off the .0f's on all the floats. That's just pure laziness.
Quote:That's just pure laziness.
Oops, guilty.

Fruny and Conner: Good examples, didn't think of overloaded functions and templates as I mostly use pure c APIs.

This topic is closed to new replies.

Advertisement