[commit: packages/base] ghc-7.8: Fixup c1035d51e to behave more like in GHC 7.6 (4254e15)
git at git.haskell.org
git at git.haskell.org
Thu Jun 26 08:33:36 UTC 2014
Repository : ssh://git@git.haskell.org/base
On branch : ghc-7.8
Link : http://ghc.haskell.org/trac/ghc/changeset/4254e158e05ac86b922dea6ba3c3c330732d991b/base
>---------------------------------------------------------------
commit 4254e158e05ac86b922dea6ba3c3c330732d991b
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date: Tue Jun 24 22:58:41 2014 +0200
Fixup c1035d51e to behave more like in GHC 7.6
The fix in c1035d51e (addressing #9231) was done under the assumption
that `Data.Fixed` is used only with power-of-10 `resolution`. This
follow-up fixup changes the behavior to be more consistent with the
previous behavior in GHC 7.6
For instance, for the following `B7` resolution
> data B7
> instance HasResolution B7 where resolution _ = 128
After this patch, the following behavior is now observable:
> 1.070 :: Fixed B7
1.062
> 1.062 :: Fixed B7
1.054
> read "1.070" :: Fixed B7
1.062
> read "1.062" :: Fixed B7
1.054
This doesn't provide the desirable "read . show == id" property
yet (which didn't hold in GHC 7.6 either), but at least `fromRational`
and `read` are consistent.
Signed-off-by: Herbert Valerio Riedel <hvr at gnu.org>
(cherry picked from commit [ec550e8f951e50fb91c89389e2e77a3358079c3a/ghc])
>---------------------------------------------------------------
4254e158e05ac86b922dea6ba3c3c330732d991b
Data/Fixed.hs | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/Data/Fixed.hs b/Data/Fixed.hs
index 984e1f3..29bc171 100644
--- a/Data/Fixed.hs
+++ b/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
More information about the ghc-commits
mailing list