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

fnpipi() : Float#

The mathematical constant pi (3.14159...).

fnee() : Float#

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

fntautau() : Float#

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

fnabsabs(x : Float) : Float#

Absolute value of a float.

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

Returns the smaller of two values.

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.

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

Returns the larger of two floats.

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

Clamps x to the range [low, high].

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

Clamps x to the range [low, high].

fnsqrtsqrt(x : Float) : Float#

Square root.

fncbrtcbrt(x : Float) : Float#

Cube root.

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

Raises base to the power exp (both Float).

fnexpexp(x : Float) : Float#

e raised to the power x.

fnexp2exp2(x : Float) : Float#

2 raised to the power x.

fnloglog(x : Float) : Float#

Natural logarithm (base e).

fnlog2log2(x : Float) : Float#

Logarithm base 2.

fnlog10log10(x : Float) : Float#

Logarithm base 10.

fnsinsin(x : Float) : Float#

Sine of x (in radians).

fncoscos(x : Float) : Float#

Cosine of x (in radians).

fntantan(x : Float) : Float#

Tangent of x (in radians).

fnasinasin(x : Float) : Float#

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

fnacosacos(x : Float) : Float#

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

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.

fnsinhsinh(x : Float) : Float#

Hyperbolic sine.

fncoshcosh(x : Float) : Float#

Hyperbolic cosine.

fntanhtanh(x : Float) : Float#

Hyperbolic tangent.

fnfloorfloor(x : Float) : Float#

Largest integer not greater than x (returns Float).

fnceilceil(x : Float) : Float#

Smallest integer not less than x (returns Float).

fnroundround(x : Float) : Float#

Rounds to the nearest integer (returns Float).

fntruncatetruncate(x : Float) : Float#

Rounds toward zero (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.