Hi guys, I'm new here.
I'm trying to wrap my head around the precision issues when handling doubles.
take a look at the following code:
the output for this code is:Code:int main() { double epsilon=0.001; double d1=2.334; double d2=2.335; cout<<"epsilon is: "<<epsilon<<endl; cout<<"d2-d1 is: "<<d2-d1<<endl; if ((d2-d1)==epsilon) cout<<"Equal!"; else cout<<"Not equal!"; }
what is going on here?Code:epsilon is: 0.001 d2-d1 is: 0.001 Not equal!
thanks for the help!