module Math:sig..end
Math contains many common mathematical functions.
val abs : int -> intabs i is the absolute value of i.
val absf : float -> floatabsf f is the absolute value of f.
val ceil : float -> intceil f is the integer closest to f in the direction of positive
infinity.
val floor : float -> intfloor f is the integer closest to f in the direction of negative
infinity.
val constrain : int -> int -> int -> intconstrain i min max is min if i <= min, max if i >= max,
or i otherwise. The behavior is undefined if min > max.
val constrainf : float -> float -> float -> floatconstrainf f min max is min if f <= min, max if f >= max,
or f otherwise. The behavior is undefined if min > max.
val dist : int -> int -> int -> int -> floatdist x1 y1 x2 y2 is the distance between the points (x1, y1) and
(x2, y2).
val distf : float -> float -> float -> float -> floatdistf x1 y1 x2 y2 is the distance between the points (x1, y1) and
(x2, y2).
val mag : int -> int -> floatmag x y is dist x y 0 0.
val magf : float -> float -> floatmagf x y is distf x y 0 0.
val lerp : int -> int -> float -> intlerp a b t is the linear interpolation from a to b by t, where
t is in [0, 1].
val lerpf : float -> float -> float -> floatlerpf a b t is the linear interpolation from a to b by t, where
t is in [0, 1].
val log : float -> float -> floatlog f b is the base-b logarithm of f.
val map : int -> int -> int -> int -> int -> intmap i low1 high1 low2 high2 is i mapped from the range [low1, high1]
to the range [low2, high2].
val mapf : float -> float -> float -> float -> float -> floatmapf f low1 high1 low2 high2 is f mapped from the range
[low1, high1] to the range [low2, high2].
val max : int -> int -> intmax a b is the maximum of a and b.
val maxf : float -> float -> floatmaxf a b is the maximum of a and b.
val min : int -> int -> intmin a b is the minimum of a and b.
val minf : float -> float -> floatminf a b is the minimum of a and b.
val norm : int -> int -> int -> floatnorm i low high is map i low high 0 1.
val normf : float -> float -> float -> floatnormf f low high is mapf f low high 0. 1..
val round : float -> intround f is the integer closest to f; 0.5 rounds up.
val sqrt : float -> floatsqrt f is the square root of f.
All functions in this section expect angles in radians.
val acos : float -> floatacos f is the inverse cosine of f. f is in [-1, 1]
and acos f is in [0, pi].
val asin : float -> floatasin f is the inverse sine of f. f is in [-1, 1] and
asin f is in [-pi/2, pi/2].
val atan : float -> floatatan f is the inverse tangent of f. f is in
[-infinity, infinity] and atan f is in [-pi/2, pi/2].
val atan2 : float -> float -> floatatan2 y x is the angle from the origin to (y, x). This function
uses the signs of x and y to determine the correct quadrant.
val cos : float -> floatcos theta is the cosine of theta.
val sin : float -> floatsin theta is the sine of theta.
val tan : float -> floattan theta is the tangent of theta.
val degrees : float -> floatdegrees theta is theta, which is in radians, converted to degrees.
val radians : float -> floatradians d is d, which is in degrees, converted to radians.
All functions in this section expect angles in radians.
val angle_avg : float -> float -> floatangle_avg theta1 theta2 is the average angle between theta1 and
theta2.
val angle_sum : float -> float -> floatangle_sum theta1 theta2 is the sum of the angles theta1 and
theta2.
val angle_diff : float -> float -> floatangle_diff theta1 theta2 is the difference between the angles theta1
and theta2.
val pi : floatpi is the constant pi. pi = 3.1415926535...
val half_pi : floathalf_pi is pi /. 2.. half_pi = 1.5707963267...
val two_pi : floattwo_pi is pi *. 2.. two_pi = 6.2831853071...
val e : floate is the constant e. e = 2.7182818284...
val random_int : ?lower_bound:int -> int -> intrandom_int bound is a random integer between 0 (inclusive) and
bound (exclusive).
val random_float : ?lower_bound:float -> float -> floatrandom_float bound is a random float between 0. (inclusive) and
bound (exclusive).
val random_bool : unit -> boolrandom_bool () is either true or false with an equal probability
of either.