Floating point representation issues

  • Thread starter Thread starter abhishek ghuwalewala
  • Start date Start date
A

abhishek ghuwalewala

The run-time is returning weird values when I do some floating point
arithmetic. For example, in the VS .NET debugger, if I try to add 0.2 (local
variable of type double) to 0.1 (local variable of type double) I get
0.300000000000000004 which messes up my other calculations. The Epsilon
trick described in the documentation for Double.Epsilon does not work
either. Is there an elegant way to work around this?

Abhishek
 
abhishek ghuwalewala said:
The run-time is returning weird values when I do some floating point
arithmetic. For example, in the VS .NET debugger, if I try to add 0.2 (local
variable of type double) to 0.1 (local variable of type double) I get
0.300000000000000004 which messes up my other calculations.

That isn't weird at all... see later.
The Epsilon
trick described in the documentation for Double.Epsilon does not work
either. Is there an elegant way to work around this?

See http://www.pobox.com/~skeet/csharp/floatingpoint.html
 
Back
Top