The NumExts interface collect together various numeric
operations that have proven to be commonly useful
-- Going between Doubles and Floats:
doubleToFloat :: Double -> Float
floatToDouble :: Float -> Double
showHex :: Integral a => a -> ShowS
showOct :: Integral a => a -> ShowS
showBin :: Integral a => a -> ShowS
showIntAtBase :: Integral a
=> a -- base
-> (a -> Char) -- digit to char
-> a -- number to show.
-> ShowS
Notes:
doubleToFloat is applied to a Double that is within
the representable range for Float, the result may be the next
higher or lower representable Float value. If the Double
is out of range, the result is undefined.floatToDouble, the floating value remains unchanged.showOct, showHex and showBin will prefix 0o,
0x and 0b, respectively. Like Numeric.showInt,
these show functions work on positive numbers only.showIntAtBase is the more general function for converting
a number at some base into a series of characters. The above
show* functions use it, for instance, here's how showHex
could be defined
showHex :: Integral a => a -> ShowS
showHex n r =
showString "0x" $
showIntAtBase 16 (toChrHex) n r
where
toChrHex d
| d < 10 = chr (ord '0' + fromIntegral d)
| otherwise = chr (ord 'a' + fromIntegral (d - 10))