X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Numeric.hs;h=d14c591731929c466ae1f26472c2a6ae3b61502d;hb=36bcfe980b04b6f083d2154909d8f1fb41e32e28;hp=1b169634a8ca1de9c843f7795546768a4b6aa9e4;hpb=9c39b06a2f4dd90de7981af27d073e247250ab5c;p=haskell-directory.git diff --git a/Numeric.hs b/Numeric.hs index 1b16963..d14c591 100644 --- a/Numeric.hs +++ b/Numeric.hs @@ -30,7 +30,6 @@ module Numeric ( showIntAtBase, -- :: Integral a => a -> (a -> Char) -> a -> ShowS showHex, -- :: Integral a => a -> ShowS showOct, -- :: Integral a => a -> ShowS - showBin, -- :: Integral a => a -> ShowS showEFloat, -- :: (RealFloat a) => Maybe Int -> a -> ShowS showFFloat, -- :: (RealFloat a) => Maybe Int -> a -> ShowS @@ -43,8 +42,6 @@ module Numeric ( ) where -import Data.Char - #ifdef __GLASGOW_HASKELL__ import GHC.Base import GHC.Read @@ -55,10 +52,12 @@ import GHC.Show import Data.Maybe import Text.ParserCombinators.ReadP( ReadP, readP_to_S, pfail ) import qualified Text.Read.Lex as L +#else +import Data.Char #endif #ifdef __HUGS__ -import PrelImpl +import Hugs.Prelude import Hugs.Numeric #endif @@ -142,36 +141,20 @@ showGFloat d x = showString (formatRealFloat FFGeneric d x) -- --------------------------------------------------------------------------- -- Integer printing functions -showIntAtBase :: Integral a => a -> (a -> Char) -> a -> ShowS +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 d in - seq c $ -- stricter than necessary - let - r' = c : r - in - if n' == 0 then r' else showIntAtBase base toChr n' r' - } - -showHex :: Integral a => a -> ShowS -showHex n r = - showString "0x" $ - showIntAtBase 16 (toChrHex) n r - where - toChrHex d - | d < 10 = chr (ord '0' + fromIntegral d) - | otherwise = chr (ord 'a' + fromIntegral (d - 10)) - -showOct :: Integral a => a -> ShowS -showOct n r = - showString "0o" $ - showIntAtBase 8 (toChrOct) n r - where toChrOct d = chr (ord '0' + fromIntegral d) - -showBin :: Integral a => a -> ShowS -showBin n r = - showString "0b" $ - showIntAtBase 2 (toChrOct) n r - where toChrOct d = chr (ord '0' + fromIntegral d) + | 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 +showOct = showIntAtBase 8 intToDigit