From 96f39afc8e9cefeab924b4215870cbfe714ea00e Mon Sep 17 00:00:00 2001 From: sof Date: Thu, 27 Aug 1998 14:35:55 +0000 Subject: [PATCH] [project @ 1998-08-27 14:35:55 by sof] floatToDigits bugfix --- ghc/lib/std/PrelNum.lhs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/ghc/lib/std/PrelNum.lhs b/ghc/lib/std/PrelNum.lhs index f2c1e45..1ae5325 100644 --- a/ghc/lib/std/PrelNum.lhs +++ b/ghc/lib/std/PrelNum.lhs @@ -1021,9 +1021,8 @@ floatToDigits base x = -- Haskell promises that p-1 <= logBase b f < p. (p - 1 + e0) * 3 `div` 10 else - ceiling ((log (fromInteger (f+1)) + - fromInt e * log (fromInteger b)) / - fromInt e * log (fromInteger b)) + ceiling ((log (fromInteger (f+1)) + fromInt e * log (fromInteger b)) / + log (fromInteger base)) fixup n = if n >= 0 then @@ -1189,15 +1188,11 @@ fromRat' x = r -- Scale x until xMin <= x < xMax, or p (the exponent) <= minExp. scaleRat :: Rational -> Int -> Rational -> Rational -> Int -> Rational -> (Rational, Int) -scaleRat b minExp xMin xMax p x = - if p <= minExp then - (x, p) - else if x >= xMax then - scaleRat b minExp xMin xMax (p+1) (x/b) - else if x < xMin then - scaleRat b minExp xMin xMax (p-1) (x*b) - else - (x, p) +scaleRat b minExp xMin xMax p x + | p <= minExp = (x, p) + | x >= xMax = scaleRat b minExp xMin xMax (p+1) (x/b) + | x < xMin = scaleRat b minExp xMin xMax (p-1) (x*b) + | otherwise = (x, p) -- Exponentiation with a cache for the most common numbers. minExpt = 0::Int -- 1.7.10.4