Safe Haskell | None |
---|
Miscellaneous functions on numbers. Things that could have gone in Numeric.
Synopsis
- binary :: Bits a => a -> String
- hex :: (Integral a, Show a) => Int -> a -> Text
- showHigit :: Int -> Maybe Char
- zeroPad :: Show a => Int -> a -> Text
- showFloat :: RealFloat a => Int -> a -> Text
- showFloatP :: RealFloat a => Bool -> Int -> a -> Text
- showFloat0 :: RealFloat a => Maybe Int -> a -> Text
- assertDiv :: Stack.HasCallStack => Integral a => a -> a -> a
- assertIntegral :: (Stack.HasCallStack, RealFrac f, Integral i) => f -> i
- readDigit :: Char -> Maybe Int
- sum :: (Foldable t, Num a) => t a -> a
- roundDigits :: (RealFrac a, Fractional b) => Int -> a -> b
- roundUp :: (Integral factor, Real a) => factor -> a -> factor
- roundDown :: (Integral factor, Real a) => factor -> a -> factor
- roundDownD :: Double -> Double -> Double
- roundToD :: Double -> Double -> Double
- 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
- asIntegral :: (RealFrac frac, Integral int) => frac -> Maybe int
- d2f :: Double -> Float
- f2d :: Float -> Double
- d2i :: Double -> Int
- i2d :: Int -> Double
- floorD :: Double -> Double
- floorF :: Float -> Float
- roundD :: Double -> Double
- roundF :: Float -> Float
show
binary :: Bits a => a -> String Source #
Show a word as binary.
Warning: for some reason, Integer is an instance of Bits, but bitSize will crash.
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.
showFloatP :: RealFloat a => Bool -> Int -> a -> Text Source #
Fancy decimal float formatting. Show up to the given precision, like
showFloat
, unless it would be all 0s. In that case, show the minimum
necessary to get to a non-zero.
showFloat0 :: RealFloat a => Maybe Int -> a -> Text Source #
Like showFloat
, but use a leading 0, so haskell can parse it.
assert
assertDiv :: Stack.HasCallStack => Integral a => a -> a -> a Source #
Like div
, but assert that it divides evenly.
assertIntegral :: (Stack.HasCallStack, RealFrac f, Integral i) => f -> i Source #
read
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.
This is linear interpolate, or lerp.
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.