X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Flib%2Fstd%2FNumeric.lhs;h=6c2811774d9131ad6d85e45ae18516c93f8a19a4;hb=ea138284b7343bb1810cfbd0284a608dc57f7d46;hp=9f7bfd9c191d3f135cd8e4707aed23112c4e9f48;hpb=6e6950259b86205b156b24fd0a4aeaca8962cbca;p=ghc-hetmet.git diff --git a/ghc/lib/std/Numeric.lhs b/ghc/lib/std/Numeric.lhs index 9f7bfd9..6c28117 100644 --- a/ghc/lib/std/Numeric.lhs +++ b/ghc/lib/std/Numeric.lhs @@ -1,6 +1,9 @@ +% ----------------------------------------------------------------------------- +% $Id: Numeric.lhs,v 1.13 2001/02/28 00:01:03 qrczak Exp $ % -% (c) The AQUA Project, Glasgow University, 1997-99 +% (c) The University of Glasgow, 1997-2000 % + \section[Numeric]{Numeric interface} Odds and ends, mostly functions for reading and showing @@ -38,13 +41,12 @@ import Char #ifndef __HUGS__ -- GHC imports import Prelude -- For dependencies -import PrelBase ( Char(..) ) +import PrelBase ( Char(..), unsafeChr ) import PrelRead -- Lots of things import PrelReal ( showSigned ) import PrelFloat ( fromRat, FFFormat(..), formatRealFloat, floatToDigits, showFloat ) -import PrelNum ( ord_0 ) #else -- Hugs imports import Array @@ -56,18 +58,17 @@ import Array \begin{code} showInt :: Integral a => a -> ShowS -showInt i rs - | i < 0 = error "Numeric.showInt: can't show negative numbers" - | otherwise = go i rs +showInt n cs + | n < 0 = error "Numeric.showInt: can't show negative numbers" + | otherwise = go n cs where - go n r = - case quotRem n 10 of { (n', d) -> - case chr (ord_0 + fromIntegral d) of { C# c# -> -- stricter than necessary - let - r' = C# c# : r - in - if n' == 0 then r' else go n' r' - }} + go n cs + | n < 10 = case unsafeChr (ord '0' + fromIntegral n) of + c@(C# _) -> c:cs + | otherwise = case unsafeChr (ord '0' + fromIntegral r) of + c@(C# _) -> go q (c:cs) + where + (q,r) = n `quotRem` 10 \end{code} Controlling the format and precision of floats. The code that @@ -75,6 +76,16 @@ implements the formatting itself is in @PrelNum@ to avoid mutual module deps. \begin{code} +{-# SPECIALIZE showEFloat :: + Maybe Int -> Float -> ShowS, + Maybe Int -> Double -> ShowS #-} +{-# SPECIALIZE showFFloat :: + Maybe Int -> Float -> ShowS, + Maybe Int -> Double -> ShowS #-} +{-# SPECIALIZE showGFloat :: + Maybe Int -> Float -> ShowS, + Maybe Int -> Double -> ShowS #-} + showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS @@ -294,7 +305,7 @@ floatToDigits base x = (p - 1 + e0) * 3 `div` 10 else ceiling ((log (fromInteger (f+1)) + - fromInt e * log (fromInteger b)) / + fromIntegral e * log (fromInteger b)) / log (fromInteger base)) fixup n = if n >= 0 then @@ -319,6 +330,6 @@ floatToDigits base x = else let bk = expt base (-k) in gen [] (r * bk) s (mUp * bk) (mDn * bk) - in (map toInt (reverse rds), k) + in (map fromIntegral (reverse rds), k) \end{code} #endif