March Docs

Math

Math module: mathematical functions and constants.

Transcendental functions (sin, cos, exp, etc.) delegate to the math_* builtins which wrap libm. Pure functions (min, max, clamp, lerp) are implemented in March.

Functions

fnabsabs(x : Float) : Float#

Absolute value of a float.

fnacosacos(x : Float) : Float#

Arc cosine, returns radians in [0, pi].

fnasinasin(x : Float) : Float#

Arc sine, returns radians in [-pi/2, pi/2].

fnatanatan(x : Float) : Float#

Arc tangent, returns radians in (-pi/2, pi/2).

fnatan2atan2(y : Float, x : Float) : Float#

Arc tangent of y/x, using signs to determine the quadrant.

fncbrtcbrt(x : Float) : Float#

Cube root.

fnceilceil(x : Float) : Float#

Smallest integer not less than x (returns Float).

fnchecked_divchecked_div(a : Int, b : Int) : Option(Int)#

Divide a by b, returning None if b is zero.

fnchecked_modchecked_mod(a : Int, b : Int) : Option(Int)#

Compute a % b, returning None if b is zero.

fnclamp_floatclamp_float(x : Float, low : Float, high : Float) : Float#

Clamps x to the range [low, high].

fnclamp_intclamp_int(x : Int, low : Int, high : Int) : Int#

Clamps x to the range [low, high].

fncoscos(x : Float) : Float#

Cosine of x (in radians).

fncoshcosh(x : Float) : Float#

Hyperbolic cosine.

fnee() : Float#

Euler's number e (2.71828...).

fnexpexp(x : Float) : Float#

e raised to the power x.

fnexp2exp2(x : Float) : Float#

2 raised to the power x.

fnfloorfloor(x : Float) : Float#

Largest integer not greater than x (returns Float).

fnlerplerp(a : Float, b : Float, t : Float) : Float#

Linear interpolation: lerp(a, b, t) = a + t*(b-a). Returns a when t=0, b when t=1.

fnloglog(x : Float) : Float#

Natural logarithm (base e).

fnlog10log10(x : Float) : Float#

Logarithm base 10.

fnlog2log2(x : Float) : Float#

Logarithm base 2.

fnmax_floatmax_float(a : Float, b : Float) : Float#

Returns the larger of two floats.

fnmax_intmax_int(a : Int, b : Int) : Int#

Returns the larger of two values.

fnmin_floatmin_float(a : Float, b : Float) : Float#

Returns the smaller of two floats.

fnmin_intmin_int(a : Int, b : Int) : Int#

Returns the smaller of two values.

fnpipi() : Float#

The mathematical constant pi (3.14159...).

fnpowpow(base : Float, exp : Float) : Float#

Raises base to the power exp (both Float).

fnroundround(x : Float) : Float#

Rounds to the nearest integer (returns Float).

fnsinsin(x : Float) : Float#

Sine of x (in radians).

fnsinhsinh(x : Float) : Float#

Hyperbolic sine.

fnsqrtsqrt(x : Float) : Float#

Square root.

fntantan(x : Float) : Float#

Tangent of x (in radians).

fntanhtanh(x : Float) : Float#

Hyperbolic tangent.

fntautau() : Float#

Tau = 2*pi (6.28318...).

fntruncatetruncate(x : Float) : Float#

Rounds toward zero (returns Float).