Karya, built on Mon Jul 24 11:39:07 PDT 2017 (patch 33511aca01257b76b88de7c7a2763b7a965c084e)

Safe HaskellNone

Util.Num

Contents

Description

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

Synopsis

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.

hex :: (Integral a, Show a) => Int -> a -> Text Source #

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.

clamp :: Ord a => a -> a -> a -> a Source #

Clamp a value to be between low and high.

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

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

inRange :: Ord a => a -> a -> a -> Bool Source #

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.

fmod :: Real a => a -> a -> a infixl 7 Source #

fmod is in a bizarre place.

fDivMod :: (Integral div, RealFrac mod) => mod -> mod -> (div, mod) Source #

d2f :: Double -> Float Source #

realToFrac doesn't preserve the special float values and is inefficient.

There are some RULEs for this, but they aren't reliable.

d2i :: Double -> Int Source #

Conversion that clamps at INT_MIN / INT_MAX.