Math

Functions for numeric computation. All trigonometric functions work in radians. Both single and float variants exist for every floating-point function — choose single for speed, float for precision.

pub fn abs(self: integer) -> integer

Absolute value. Removes the sign from a negative integer.

pub fn floor_mod(self: integer, divisor: integer) -> integer?

Floor modulo — the remainder that takes the sign of the DIVISOR, so x.floor_mod(n) lands in [0, n) for a positive n. The % operator truncates toward zero and keeps the DIVIDEND's sign (-1 % 3 == -1); floor_mod wraps ((-1).floor_mod(3) == 2), which is what circular indexing / wrap-around wants (grid[(i - 1).floor_mod(w)]). x.floor_mod(0) is null, like % (C80 — an undefined value is a null, never a fault).

pub fn abs(self: single) -> single

Absolute value for single-precision floats.

pub fn cos(self: single) -> single

Cosine. Use for circular motion: x = r * cos(angle).

pub fn sin(self: single) -> single

Sine. Use for circular motion: y = r * sin(angle).

pub fn tan(self: single) -> single

Tangent. Use for slopes and perspective projection.

pub fn acos(self: single) -> single?

Arc cosine. Returns the angle (in radians) whose cosine is the value; null outside [-1, 1].

pub fn asin(self: single) -> single?

Arc sine. Returns the angle whose sine is the value; null outside [-1, 1].

pub fn atan(self: single) -> single

Arc tangent of a single value. Returns angle in (-PI/2, PI/2).

pub fn ceil(self: single) -> single

Round up to the nearest integer value. Use to compute required buffer sizes from fractional counts.

pub fn floor(self: single) -> single

Round down to the nearest integer value. Use to convert a float position to a tile index.

pub fn round(self: single) -> single

Round to the nearest integer value (half rounds away from zero).

pub fn sqrt(self: single) -> single?

Square root. Use for distances and normalization. Null for a negative value.

pub fn atan2(self: single, v2: single) -> single

Arc tangent of y/x as y.atan2(x), preserving the correct quadrant: atan2(1.0, 0.0) is PI/2. Use instead of atan when you have separate x/y components.

pub fn log(self: single, v2: single) -> single?

Logarithm in the base given second: log(8.0, 2.0) is 3. Null for a negative value, -inf at 0. Use for converting between scales (e.g., decibels).

pub fn pow(self: integer, v2: integer) -> integer?

Raises the integer to the power given second: pow(3, 4) is 81, and 3 ** 20 is 3486784401 exactly. Null when the exponent is negative (no integer answers it) or the answer does not fit an integer (pow(2, 63)), as * answers null past the range.

pub fn pow(self: single, v2: single) -> single?

Raises the value to the power given second: pow(2.0, 10.0) is 1024. Null when the answer is not a real number (pow(-8.0, 0.5)). Use for exponential growth curves and scaling.

pub fn abs(self: float) -> float

Absolute value for double-precision floats.

pub PI = OpMathPiFloat()

The ratio of a circle's circumference to its diameter (3.14159...).

pub E = OpMathEFloat()

Euler's number, the base of natural logarithms (2.71828...).

pub fn cos(self: float) -> float

Cosine. Use for circular motion: x = r * cos(angle).

pub fn sin(self: float) -> float

Sine. Use for circular motion: y = r * sin(angle).

pub fn tan(self: float) -> float

Tangent. Use for slopes and perspective projection.

pub fn acos(self: float) -> float?

Arc cosine. Returns the angle (in radians) whose cosine is the value; null outside [-1, 1].

pub fn asin(self: float) -> float?

Arc sine. Returns the angle whose sine is the value; null outside [-1, 1].

pub fn atan(self: float) -> float

Arc tangent of a single value. Returns angle in (-PI/2, PI/2).

pub fn ceil(self: float) -> float

Round up to the nearest integer value. Use to compute required buffer sizes from fractional counts.

pub fn floor(self: float) -> float

Round down to the nearest integer value. Use to convert a float position to a tile index.

pub fn round(self: float) -> float

Round to the nearest integer value (half rounds away from zero).

pub fn sqrt(self: float) -> float?

Square root. Use for distances and normalization. Null for a negative value.

pub fn atan2(self: float, v2: float) -> float

Arc tangent of y/x as y.atan2(x), preserving the correct quadrant: atan2(1.0, 0.0) is PI/2. Use instead of atan when you have separate x/y components.

pub fn log(self: float, v2: float) -> float?

Logarithm in the base given second: log(8.0, 2.0) is 3. Null for a negative value, -inf at 0. Use for converting between scales (e.g., decibels).

pub fn pow(self: float, v2: float) -> float?

Raises the value to the power given second: pow(2.0, 10.0) is 1024. Null when the answer is not a real number (pow(-8.0, 0.5)). Use for exponential growth curves and scaling.