diff options
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/Data/Fixed.hs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/libraries/base/Data/Fixed.hs b/libraries/base/Data/Fixed.hs index b3af208469..cadbb61ac1 100644 --- a/libraries/base/Data/Fixed.hs +++ b/libraries/base/Data/Fixed.hs @@ -159,9 +159,12 @@ instance (HasResolution a) => Read (Fixed a) where convertFixed :: forall a . HasResolution a => Lexeme -> ReadPrec (Fixed a) convertFixed (Number n) | Just (i, f) <- numberToFixed e n = - return (fromInteger i + (fromInteger f / fromInteger r)) - where r = resolution (undefined :: Fixed a) -- = 10^e - e = round (logBase 10 (fromInteger r) :: Double) + return (fromInteger i + (fromInteger f / (10 ^ e))) + where r = resolution (undefined :: Fixed a) + -- round 'e' up to help make the 'read . show == id' property + -- possible also for cases where 'resolution' is not a + -- power-of-10, such as e.g. when 'resolution = 128' + e = ceiling (logBase 10 (fromInteger r) :: Double) convertFixed _ = pfail data E0 = E0 |