I am attempting to calculate the machine epsilon value for doubles and floats in C++ as part of a school assignment. I'm using Cygwin in Windows 7, 64 bit, here is the code:
#include <iostream>
int main() {
double epsilon = 1;
while(1 + epsilon > 1)
epsilon = epsilon / 2;
epsilon = 2*epsilon;
std::cout << epsilon << std::endl;
float epsilon_f = 1;
while(1 + epsilon_f > 1)
epsilon_f = epsilon_f / 2;
epsilon_f = 2*epsilon_f;
std::cout << epsilon_f << std::endl;
return 1;
}
When I run the code, I receive 1.0842e-019 for both values. I looked it up and should be getting 2.22e-16 for the double, and 1.19e-07 for the float value. When I run the exact same code on a Macbook, the code returns the correct values. What could be causing the discrepancy on my Windows machine?