2 % (c) The AQUA Project, Glasgow University, 1998
5 \section[NumExts]{Misc numeric bits}
11 doubleToFloat -- :: Double -> Float
12 , floatToDouble -- :: Double -> Float
13 , showHex -- :: Integral a => a -> ShowS
14 , showOct -- :: Integral a => a -> ShowS
17 import Char (ord, chr)
18 import PrelBase (ord_0)
23 doubleToFloat :: Double -> Float
24 doubleToFloat (D# d#) = F# (double2Float# d#)
26 floatToDouble :: Float -> Double
27 floatToDouble (F# f#) = D# (float2Double# f#)
29 showIntAtBase :: Integral a => a -> (a -> Char) -> a -> ShowS
30 showIntAtBase base toChr n r
31 | n < 0 = error ("NumExts.showIntAtBase: applied to negative number " ++ show n)
33 case quotRem n base of { (n', d) ->
34 case toChr d of { C# c# -> -- stricter than necessary
38 if n' == 0 then r' else showIntAtBase base toChr n' r'
41 showHex :: Integral a => a -> ShowS
44 showIntAtBase 16 (toChrHex) n r
47 | d < 10 = chr (ord_0 + fromIntegral d)
48 | otherwise = chr (ord 'a' + fromIntegral (d - 10))
50 showOct :: Integral a => a -> ShowS
53 showIntAtBase 8 (toChrOct) n r
54 where toChrOct d = chr (ord_0 + fromIntegral d)