2 % (c) The AQUA Project, Glasgow University, 1997
4 \section[Numeric]{Numeric interface}
6 Odds and ends, mostly functions for reading and showing
7 \tr{RealFloat}-like kind of values.
10 {-# OPTIONS -fno-implicit-prelude #-}
19 readDec, readOct, readHex,
20 showDec, showOct, showHex,
40 %*********************************************************
42 \subsection{Signatures}
44 %*********************************************************
49 fromRat :: (RealFloat a) => Rational -> a
51 showSigned :: (Real a) => (a -> ShowS) -> Int -> a -> ShowS
52 readSigned :: (Real a) => ReadS a -> ReadS a
54 showInt :: Integral a => a -> ShowS
55 readInt :: (Integral a) => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a
57 readDec :: (Integral a) => ReadS a
58 readOct :: (Integral a) => ReadS a
59 readHex :: (Integral a) => ReadS a
61 showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
62 showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
63 showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
64 showFloat :: (RealFloat a) => a -> ShowS
66 readFloat :: (RealFloat a) => ReadS a
68 floatToDigits :: (RealFloat a) => Integer -> a -> ([Int], Int)
69 lexDigits :: ReadS String
73 showInt :: Integral a => a -> ShowS
75 = case quotRem n 10 of { (n', d) ->
76 case chr (ord_0 + fromIntegral d) of { C# c# -> -- stricter than necessary
80 if n' == 0 then r' else showInt n' r'
83 showIntAtBase :: Integral a => a -> (a -> Char) -> a -> ShowS
84 showIntAtBase base toChr n r
85 = case quotRem n base of { (n', d) ->
86 case toChr d of { C# c# -> -- stricter than necessary
90 if n' == 0 then r' else showIntAtBase base toChr n' r'
93 showDec :: Integral a => a -> ShowS
96 (\ d -> chr (ord_0 + fromIntegral d))
99 showHex :: Integral a => a -> ShowS
102 showIntAtBase 16 (toChrHex) n r
106 chr (ord_0 + fromIntegral d)
108 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)
119 showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
120 showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
121 showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
123 showEFloat d x = showString (formatRealFloat FFExponent d x)
124 showFFloat d x = showString (formatRealFloat FFFixed d x)
125 showGFloat d x = showString (formatRealFloat FFGeneric d x)