Simple rand() question
It's like 10f, it tells the compiler it's a floating point number, not an int or a double. It's the same as 10.0f too just fyi which is how I normally do it (with the decimal) so I don't confuse it.
Quote:
It's like 10f, it tells the compiler it's a floating point number, not an int or a double. It's the same as 10.0f too just fyi which is how I normally do it (with the decimal) so I don't confuse it.
I thought adding the decimal point was just as good as adding the f. So 10.0 was the same as 10f.
- Goishin
Sure there's a difference. Consider this program:
If you didn't use the f-suffix you wouldn't be able to call the float verion of function. Which is to say that by default 10.0 is a double while 10.0f is a float. See this part of the draft standard.
#include <iostream>float function(float alpha, float beta){ return alpha + beta;}double function(double alpha, double beta){ return alpha * beta;}int main(){ std::cout << "If you multiply 10 and 20 you get: " << function(10.0, 20.0) << std::endl; std::cout << "If you add 10 and 20 you get: " << function(10.0f, 20.0f) << std::endl;}
If you didn't use the f-suffix you wouldn't be able to call the float verion of function. Which is to say that by default 10.0 is a double while 10.0f is a float. See this part of the draft standard.
Quote:The type of a floating literal is double unless explicitly specified by a suffix.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement