2 <label id="sec:NumExts">
5 The <tt/NumExts/ interface collect together various numeric
6 operations that have proven to be commonly useful
9 -- Going between Doubles and Floats:
10 doubleToFloat :: Double -> Float
11 floatToDouble :: Float -> Double
13 showHex :: Integral a => a -> ShowS
14 showOct :: Integral a => a -> ShowS
15 showBin :: Integral a => a -> ShowS
17 showIntAtBase :: Integral a
19 -> (a -> Char) -- digit to char
20 -> a -- number to show.
27 If <tt/doubleToFloat/ is applied to a <tt/Double/ that is within
28 the representable range for <tt/Float/, the result may be the next
29 higher or lower representable <tt/Float/ value. If the <tt/Double/
30 is out of range, the result is undefined.
32 No loss of precision occurs in the other direction with
33 <tt/floatToDouble/, the floating value remains unchanged.
35 <tt/showOct/, <tt/showHex/ and <tt/showBin/ will prefix <tt/0o/,
36 <tt/0x/ and <tt/0b/, respectively. Like <tt/Numeric.showInt/,
37 these show functions work on positive numbers only.
39 <tt/showIntAtBase/ is the more general function for converting
40 a number at some base into a series of characters. The above
41 <tt/show*/ functions use it, for instance, here's how <tt/showHex/
47 showHex :: Integral a => a -> ShowS
50 showIntAtBase 16 (toChrHex) n r
53 | d < 10 = chr (ord '0' + fromIntegral d)
54 | otherwise = chr (ord 'a' + fromIntegral (d - 10))