[Haskell-cafe] rounding errors with real numbers.

Brian Hulley brianh at metamilk.com
Sun Feb 26 12:06:11 EST 2006

Matthias Fischmann wrote:
>|     -- fix rounding error:
>|     repair [i] = [upper]
>|     repair (h:t) = h : repair t

Just to point out that this only fixes the last element of the list, so 
inputs like [1,2,10.8,10.8] would not be handled properly if you require the 
same input values to map to the same output values (I assume such inputs 
don't arise in the context you're using but in a general context the above 
wouldn't be a solution).

Another thing is that when using floating point numbers, is there really any 
difference between 1.0 and 0.9999999 anyway? It's usually not recommended to 
ever test floats for equality since, depending on the architecture, the 
"same" float can end up being represented differently depending on what 
optimizations are happening eg an implementation could conceivably be making 
use of two different fp units if values are passed between different 
concurrently executing threads in a multi-processor or distributed 
processing environment...

Regards, Brian. 

More information about the Haskell-Cafe mailing list