floating: Make fromRational work properly.
commit3f71fe3998c947cd80218406ebe9b78a4e27399e
authorNick Bowler <nbowler@draconx.ca>
Fri, 19 Feb 2010 22:47:59 +0000 (19 17:47 -0500)
committerNick Bowler <nbowler@draconx.ca>
Fri, 19 Feb 2010 22:48:08 +0000 (19 17:48 -0500)
treeb2a8a052bdd7f930c1ba583501aef157e4e4058e
parent851ccb5520035c38a8c2103e9569c4b302aa7d80
floating: Make fromRational work properly.

The current implementation of fromRational (for both floating types) is
a simple floating point division, which does not work correctly when
either the numerator or the denominator cannot be represented exactly.

We do a correct conversion by scaling the rational by a power of two to
get a large integer that makes maximum use of the available precision.
Since such an integer is exactly representable, we can use scalb to get
the actual value.
Data/Floating/Helpers.hs [new file with mode: 0644]
Data/Floating/Types/Double.hs
Data/Floating/Types/Float.hs
altfloat.cabal