Std\Math
Math — polymorphic numeric operations and float math.
The Num trait provides polymorphic abs, max, min for both
Int and Float. Float-specific functions (sqrt, sin, cos, etc.) are
bound from the C math library via extern declarations.
Traits
Section titled “Traits”trait Num a abs : a -> a max : a -> a -> a min : a -> a -> a negate : a -> aendNumeric trait — polymorphic over Int and Float.
Functions
Section titled “Functions”abs : a -> a
Section titled “abs : a -> a”max : a -> a -> a
Section titled “max : a -> a -> a”min : a -> a -> a
Section titled “min : a -> a -> a”negate : a -> a
Section titled “negate : a -> a”clamp : Int -> Int -> Int -> Int
Section titled “clamp : Int -> Int -> Int -> Int”Restricts a value to the range [lo, hi].
clamp 0 10 15 # => 10sign : Int -> Int
Section titled “sign : Int -> Int”Returns 1 for positive, -1 for negative, 0 for zero.
sign 42 # => 1isEven : Int -> Bool
Section titled “isEven : Int -> Bool”Returns true if the integer is even.
isOdd : Int -> Bool
Section titled “isOdd : Int -> Bool”Returns true if the integer is odd.
gcd : Int -> Int -> Int
Section titled “gcd : Int -> Int -> Int”Greatest common divisor (Euclidean algorithm).
gcd 12 8 # => 4pow : Int -> Int -> Int
Section titled “pow : Int -> Int -> Int”Integer exponentiation. Uses fast squaring.
pow 2 10 # => 1024factorial : Int -> Int
Section titled “factorial : Int -> Int”Factorial: n! = 1 * 2 * ... * n.
factorial 5 # => 120sqrt : Float -> Float
Section titled “sqrt : Float -> Float”Square root (Float -> Float).
sin : Float -> Float
Section titled “sin : Float -> Float”Sine (Float -> Float, radians).
cos : Float -> Float
Section titled “cos : Float -> Float”Cosine (Float -> Float, radians).
tan : Float -> Float
Section titled “tan : Float -> Float”Tangent (Float -> Float, radians).
log : Float -> Float
Section titled “log : Float -> Float”Natural logarithm (Float -> Float).
exp : Float -> Float
Section titled “exp : Float -> Float”Exponential e^x (Float -> Float).
floor : Float -> Float
Section titled “floor : Float -> Float”Floor (Float -> Float).
ceil : Float -> Float
Section titled “ceil : Float -> Float”Ceiling (Float -> Float).
round : Float -> Float
Section titled “round : Float -> Float”Round to nearest integer (Float -> Float).
pi : Float = 3.141592653589793
Section titled “pi : Float = 3.141592653589793”Pi constant.
pi # => 3.14159265358979