2 % (c) The AQUA Project, Glasgow University, 1997-98
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 #-}
20 readDec, readOct, readHex,
21 showDec, showOct, showHex,
42 %*********************************************************
44 \subsection[Numeric-signatures]{Signatures}
46 %*********************************************************
51 fromRat :: (RealFloat a) => Rational -> a
53 showSigned :: (Real a) => (a -> ShowS) -> Int -> a -> ShowS
54 readSigned :: (Real a) => ReadS a -> ReadS a
56 showInt :: Integral a => a -> ShowS
57 readInt :: (Integral a) => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a
59 readDec :: (Integral a) => ReadS a
60 readOct :: (Integral a) => ReadS a
61 readHex :: (Integral a) => ReadS a
63 showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
64 showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
65 showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
66 showFloat :: (RealFloat a) => a -> ShowS
68 readFloat :: (RealFloat a) => ReadS a
70 floatToDigits :: (RealFloat a) => Integer -> a -> ([Int], Int)
71 lexDigits :: ReadS String
75 showInt :: Integral a => a -> ShowS
77 = case quotRem n 10 of { (n', d) ->
78 case chr (ord_0 + fromIntegral d) of { C# c# -> -- stricter than necessary
82 if n' == 0 then r' else showInt n' r'
85 showIntAtBase :: Integral a => a -> (a -> Char) -> a -> ShowS
86 showIntAtBase base toChr n r
87 = case quotRem n base of { (n', d) ->
88 case toChr d of { C# c# -> -- stricter than necessary
92 if n' == 0 then r' else showIntAtBase base toChr n' r'
95 showDec :: Integral a => a -> ShowS
98 (\ d -> chr (ord_0 + fromIntegral d))
101 showHex :: Integral a => a -> ShowS
104 showIntAtBase 16 (toChrHex) n r
107 | d < 10 = chr (ord_0 + fromIntegral d)
108 | otherwise = chr (ord 'a' + fromIntegral (d - 10))
110 showOct :: Integral a => a -> ShowS
113 showIntAtBase 8 (toChrOct) n r
114 where toChrOct d = chr (ord_0 + fromIntegral d)
118 Controlling the format and precision of floats. The code that
119 implements the formatting itself is in @PrelNum@ to avoid
123 showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
124 showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
125 showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
127 showEFloat d x = showString (formatRealFloat FFExponent d x)
128 showFFloat d x = showString (formatRealFloat FFFixed d x)
129 showGFloat d x = showString (formatRealFloat FFGeneric d x)