Safe Haskell | None |
---|

Miscellaneous functions on numbers. Things that could have gone in Numeric.

- binary :: Bits.Bits a => a -> String
- hex :: (Integral a, Show a) => Int -> a -> Text
- showHigit :: Int -> Maybe Char
- readDigit :: Char -> Maybe Int
- showFloat :: RealFloat a => Int -> a -> Text
- showFloat0 :: RealFloat a => Maybe Int -> a -> Text
- roundDigits :: (RealFrac a, Fractional b) => Int -> a -> b
- roundUp :: (Integral factor, Real a) => factor -> a -> factor
- clamp :: Ord a => a -> a -> a -> a
- restrict :: Real a => a -> a -> a -> a
- inRange :: Ord a => a -> a -> a -> Bool
- scale :: (Eq a, Num a) => a -> a -> a -> a
- normalize :: (Eq a, Fractional a) => a -> a -> a -> a
- fmod :: Real a => a -> a -> a
- fDivMod :: (Integral div, RealFrac mod) => mod -> mod -> (div, mod)
- integral :: RealFrac a => a -> Bool
- d2f :: Double -> Float
- f2d :: Float -> Double
- d2i :: Double -> Int

# show

binary :: Bits.Bits a => a -> String Source #

Show a word as binary.

Warning: for some reason, Integer is an instance of Bits, but bitSize will crash.

# read

# show

showFloat :: RealFloat a => Int -> a -> Text Source #

Display a float with the given precision, dropping trailing and leading zeros. Haskell requires a 0 before the decimal point, so this produces non-Haskell numbers.

showFloat0 :: RealFloat a => Maybe Int -> a -> Text Source #

Like `showFloat`

, but use a leading 0, so haskell can parse it.

# transform

roundDigits :: (RealFrac a, Fractional b) => Int -> a -> b Source #

roundUp :: (Integral factor, Real a) => factor -> a -> factor Source #

Round up to the nearest factor above the given number.

restrict :: Real a => a -> a -> a -> a Source #

Confine the given value lie between the first two arguments, but using modulus, not clamping.

scale :: (Eq a, Num a) => a -> a -> a -> a Source #

Scale `v`

, which is between 0 and 1 inclusive, to be between `low`

and
`high`

. If `v`

is not in the 0--1 range, the result will be out of the
low--high range.

normalize :: (Eq a, Fractional a) => a -> a -> a -> a Source #

Normalize `v`

, which is between `low`

and `high`

inclusive, to be between
0 and 1. As with `scale`

, if `v`

is not in range, the result will not be
in range either.