Hi, I'm trying to investigate a weird mathematical problem I've come across using G++. I only have G++ on SuSE 9.1, and so I'm unable to test the code on other systems, kernels etc. I would be grateful if someone could compile and run this code and let me have the results:
#include <iostream> #include <math.h>
int main() { float l = 45.4567; float d = floorf(l); float m = floorf((l - d) * 60.); float s = (((l - d) * 60.) - m) * 60.;
std::cout << "l = " << l << std::endl; std::cout << "d = " << d << std::endl; std::cout << "l-d = " << l - d << std::endl; std::cout << "(l-d) * 60.0 = " << (l - d) * 60. << std::endl; std::cout << "m = " << m << std::endl; std::cout << "s = " << s << std::endl;
float r = (s / 3600.) + (m / 60.) + d; std::cout << "reconstructed= " << r << std::endl;
return 0; }
Basically, I getting an odd value printed for l - d (it comes out as 0.456699 and not 0.4567 as expected).
Many thanks,
Stuart.