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.
11 {-# OPTIONS -fno-implicit-prelude #-}
20 readDec, readOct, readHex,
21 showDec, showOct, showHex,
41 %*********************************************************
43 \subsection{Signatures}
45 %*********************************************************
50 fromRat :: (RealFloat a) => Rational -> a
52 showSigned :: (Real a) => (a -> ShowS) -> Int -> a -> ShowS
53 readSigned :: (Real a) => ReadS a -> ReadS a
55 showInt :: Integral a => a -> ShowS
56 readInt :: (Integral a) => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a
58 readDec :: (Integral a) => ReadS a
59 readOct :: (Integral a) => ReadS a
60 readHex :: (Integral a) => ReadS a
62 showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
63 showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
64 showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
65 showFloat :: (RealFloat a) => a -> ShowS
67 readFloat :: (RealFloat a) => ReadS a
69 floatToDigits :: (RealFloat a) => Integer -> a -> ([Int], Int)
70 lexDigits :: ReadS String
74 showInt :: Integral a => a -> ShowS
76 = case quotRem n 10 of { (n', d) ->
77 case chr (ord_0 + fromIntegral d) of { C# c# -> -- stricter than necessary
81 if n' == 0 then r' else showInt n' r'
84 showIntAtBase :: Integral a => a -> (a -> Char) -> a -> ShowS
85 showIntAtBase base toChr n r
86 = case quotRem n base of { (n', d) ->
87 case toChr d of { C# c# -> -- stricter than necessary
91 if n' == 0 then r' else showIntAtBase base toChr n' r'
94 showDec :: Integral a => a -> ShowS
97 (\ d -> chr (ord_0 + fromIntegral d))
100 showHex :: Integral a => a -> ShowS
103 showIntAtBase 16 (toChrHex) n r
107 chr (ord_0 + fromIntegral d)
109 chr (ord 'a' + fromIntegral (d - 10))
111 showOct :: Integral a => a -> ShowS
114 showIntAtBase 8 (toChrOct) n r
115 where toChrOct d = chr (ord_0 + fromIntegral d)
120 showEFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
121 showFFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
122 showGFloat :: (RealFloat a) => Maybe Int -> a -> ShowS
124 showEFloat d x = showString (formatRealFloat FFExponent d x)
125 showFFloat d x = showString (formatRealFloat FFFixed d x)
126 showGFloat d x = showString (formatRealFloat FFGeneric d x)