Tuesday, 6 August 2013

Same floating point operation, different results

Same floating point operation, different results

I really can't wrap my head around the fact that this code gives 2 results
for the same formula:
#include <iostream>
#include <cmath>
int main() {
// std::cout.setf(std::ios::fixed, std::ios::floatfield);
std::cout.precision(20);
float a = (exp(M_PI) - M_PI);
std::cout << (exp(M_PI) - M_PI) << "\n";
std::cout << a << "\n";
return (0);
}
I don't really think that the IEEE 754 floating point representation is
playing a significant role here ...

No comments:

Post a Comment