Hi,
*Main> 0.2 + 0.1
0.30000000000000004
Prelude> (0.1 :: Float) + (0.2 :: Float)
0.3
Prelude> (0.1 :: Double) + (0.2 :: Double)
0.30000000000000004
Prelude> (0.1 :: Float) + 0.2 == 0.3
True
If you use Float's instead of doubles, it stores less precision, and
so gets it right.
Also, if what you really want is decimals, why not:
data Decimal = Decimal {dps :: Integer, value :: Integer}
Then define your Num instance on Decimal, and have perfect high
fidelity numbers throughout.
Thanks
Neil
_______________________________________________
Glasgow-haskell-users mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users