Float compile-time calculation not happening?
- by Klaim
A little test program:
#include <iostream>
const float TEST_FLOAT = 1/60;
const float TEST_A = 1;
const float TEST_B = 60;
const float TEST_C = TEST_A / TEST_B;
int main()
{
std::cout << TEST_FLOAT << std::endl;
std::cout << TEST_C << std::endl;
std::cin.ignore();
return 0;
}
Result :
0
0.0166667
Tested on Visual Studio 2008 & 2010.
I worked on other compilers that, if I remember well, made the first result like the second result. Now my memory could be wrong, but shouldn't TEST_FLOAT have the same value than TEST_C? If not, why?
Is TEST_C value resolved at compile time or at runtime? I always assumed the former but now that I see those results I have some doubts...