From: sof Date: Fri, 12 Dec 2003 18:29:26 +0000 (+0000) Subject: [project @ 2003-12-12 18:29:26 by sof] X-Git-Tag: nhc98-1-18-release~432 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=16a14a4e9f91677590f15ec97f47b70e1fe50533;p=ghc-base.git [project @ 2003-12-12 18:29:26 by sof] showIntAtBase: - implementation uses quotRem [where the remainder isn't always non-negative -- ditto for divMod, so there's no trivial fix], negative bases aren't supported; catch this. - separate argument validity checking from actual digitisation. --- diff --git a/Numeric.hs b/Numeric.hs index d55f9bb..bde290d 100644 --- a/Numeric.hs +++ b/Numeric.hs @@ -143,16 +143,17 @@ showGFloat d x = showString (formatRealFloat FFGeneric d x) showIntAtBase :: Integral a => a -> (Int -> Char) -> a -> ShowS showIntAtBase base toChr n r - | n < 0 = error ("Numeric.showIntAtBase: applied to negative number " ++ show n) - | otherwise = - case quotRem n base of { (n', d) -> - let c = toChr (fromIntegral d) in - seq c $ -- stricter than necessary - let - r' = c : r - in - if n' == 0 then r' else showIntAtBase base toChr n' r' - } + | base <= 1 = error ("Numeric.showIntAtBase: applied to unsupported base " ++ show base) + | n < 0 = error ("Numeric.showIntAtBase: applied to negative number " ++ show n) + | otherwise = showIt (quotRem n base) r + where + showIt (n,d) r = seq c $ -- stricter than necessary + case n of + 0 -> r' + _ -> showIt (quotRem n base) r' + where + c = toChr (fromIntegral d) + r' = c : r showHex, showOct :: Integral a => a -> ShowS showHex = showIntAtBase 16 intToDigit