diff options
author | simonm <unknown> | 1998-02-02 17:35:59 +0000 |
---|---|---|
committer | simonm <unknown> | 1998-02-02 17:35:59 +0000 |
commit | 28139aea50376444d56f43f0914291348a51a7e7 (patch) | |
tree | 595c378188638ef16462972c1e7fcdb8409c7f16 /ghc/lib/std/Numeric.lhs | |
parent | 98a1ebecb6d22d793b1d9f8e1d24ecbb5a2d130f (diff) | |
download | haskell-28139aea50376444d56f43f0914291348a51a7e7.tar.gz |
[project @ 1998-02-02 17:27:26 by simonm]
Library re-organisation:
All libraries now live under ghc/lib, which has the following structure:
ghc/lib/std -- all prelude files (libHS.a)
ghc/lib/std/cbits
ghc/lib/exts -- standard Hugs/GHC extensions (libHSexts.a)
-- available with '-fglasgow-exts'
ghc/lib/posix -- POSIX library (libHSposix.a)
ghc/lib/posix/cbits -- available with '-syslib posix'
ghc/lib/misc -- used to be hslibs/ghc (libHSmisc.a)
ghc/lib/misc/cbits -- available with '-syslib misc'
ghc/lib/concurrent -- Concurrent libraries (libHSconc.a)
-- available with '-concurrent'
Also, several non-standard prelude modules had their names changed to begin
with 'Prel' to reduce namespace pollution.
Addr ==> PrelAddr (Addr interface available in 'exts')
ArrBase ==> PrelArr
CCall ==> PrelCCall (CCall interface available in 'exts')
ConcBase ==> PrelConc
GHCerr ==> PrelErr
Foreign ==> PrelForeign (Foreign interface available in 'exts')
GHC ==> PrelGHC
IOHandle ==> PrelHandle
IOBase ==> PrelIOBase
GHCmain ==> PrelMain
STBase ==> PrelST
Unsafe ==> PrelUnsafe
UnsafeST ==> PrelUnsafeST
Diffstat (limited to 'ghc/lib/std/Numeric.lhs')
-rw-r--r-- | ghc/lib/std/Numeric.lhs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/ghc/lib/std/Numeric.lhs b/ghc/lib/std/Numeric.lhs new file mode 100644 index 0000000000..067c6728b1 --- /dev/null +++ b/ghc/lib/std/Numeric.lhs @@ -0,0 +1,98 @@ +% +% (c) The AQUA Project, Glasgow University, 1997-98 +% +\section[Numeric]{Numeric interface} + +Odds and ends, mostly functions for reading and showing +\tr{RealFloat}-like kind of values. + + +\begin{code} +{-# OPTIONS -fno-implicit-prelude #-} +module Numeric + ( + fromRat, + showSigned, + readSigned, + showInt, + readInt, + + readDec, readOct, readHex, + + showEFloat, + showFFloat, + showGFloat, + showFloat, + readFloat, + + floatToDigits, + lexDigits + + ) where + +import PrelBase +import PrelMaybe +import PrelArr +import PrelNum +import PrelRead + +\end{code} + +%********************************************************* +%* * +\subsection[Numeric-signatures]{Signatures} +%* * +%********************************************************* + +Interface on offer: + +\begin{pseudocode} +fromRat :: (RealFloat a) => Rational -> a + +showSigned :: (Real a) => (a -> ShowS) -> Int -> a -> ShowS +readSigned :: (Real a) => ReadS a -> ReadS a + +showInt :: Integral a => a -> ShowS +readInt :: (Integral a) => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a + +readDec :: (Integral a) => ReadS a +readOct :: (Integral a) => ReadS a +readHex :: (Integral a) => ReadS a + +showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS +showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS +showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS +showFloat :: (RealFloat a) => a -> ShowS + +readFloat :: (RealFloat a) => ReadS a + +floatToDigits :: (RealFloat a) => Integer -> a -> ([Int], Int) +lexDigits :: ReadS String +\end{pseudocode} + +\begin{code} +showInt :: Integral a => a -> ShowS +showInt 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 showInt n' r' + }} +\end{code} + +Controlling the format and precision of floats. The code that +implements the formatting itself is in @PrelNum@ to avoid +mutual module deps. + +\begin{code} +showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS +showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS +showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS + +showEFloat d x = showString (formatRealFloat FFExponent d x) +showFFloat d x = showString (formatRealFloat FFFixed d x) +showGFloat d x = showString (formatRealFloat FFGeneric d x) + +\end{code} |