2 % (c) The AQUA Project, Glasgow University, 1997-99
4 \section[Numeric]{Numeric interface}
6 Odds and ends, mostly functions for reading and showing
7 \tr{RealFloat}-like kind of values.
11 {-# OPTIONS -fno-implicit-prelude #-}
14 ( fromRat -- :: (RealFloat a) => Rational -> a
15 , showSigned -- :: (Real a) => (a -> ShowS) -> Int -> a -> ShowS
16 , readSigned -- :: (Real a) => ReadS a -> ReadS a
17 , showInt -- :: Integral a => a -> ShowS
18 , readInt -- :: (Integral a) => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a
20 , readDec -- :: (Integral a) => ReadS a
21 , readOct -- :: (Integral a) => ReadS a
22 , readHex -- :: (Integral a) => ReadS a
24 , showEFloat -- :: (RealFloat a) => Maybe Int -> a -> ShowS
25 , showFFloat -- :: (RealFloat a) => Maybe Int -> a -> ShowS
26 , showGFloat -- :: (RealFloat a) => Maybe Int -> a -> ShowS
27 , showFloat -- :: (RealFloat a) => a -> ShowS
28 , readFloat -- :: (RealFloat a) => ReadS a
31 , floatToDigits -- :: (RealFloat a) => Integer -> a -> ([Int], Int)
32 , lexDigits -- :: ReadS String
34 -- Implementation checked wrt. Haskell 98 lib report, 1/99.
44 import PrelErr ( error )
49 showInt :: Integral a => a -> ShowS
51 | i < 0 = error "Numeric.showInt: can't show negative numbers"
55 case quotRem n 10 of { (n', d) ->
56 case chr (ord_0 + fromIntegral d) of { C# c# -> -- stricter than necessary
60 if n' == 0 then r' else go n' r'
64 Controlling the format and precision of floats. The code that
65 implements the formatting itself is in @PrelNum@ to avoid
69 showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
70 showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
71 showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
73 showEFloat d x = showString (formatRealFloat FFExponent d x)
74 showFFloat d x = showString (formatRealFloat FFFixed d x)
75 showGFloat d x = showString (formatRealFloat FFGeneric d x)