Math

Functions for numeric computation. All trigonometric functions work in radians. Both single and float variants exist for every floating-point function — `single` stores a value in half the space, `float` keeps the 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: f64) -> f64

Absolute value for double-precision floats.

pub fn bits(self: f64) -> i64

The 64 bits of a double as they are stored (IEEE-754 binary64), moved, not converted: what a byte format writes for it. float_from_bits takes them back. -0.0's pattern is the integer null's, so (-0.0).bits() reads as null and still comes back as -0.0.

pub fn float_from_bits(v: i64) -> f64

The double whose stored bits are v (IEEE-754 binary64): bits() taken back.

pub fn bits(self: single) -> integer

The 32 bits of a single as they are stored (IEEE-754 binary32), as a signed 32-bit value.

pub fn single_from_bits(v: integer) -> single

The single whose stored bits are v (IEEE-754 binary32): bits() taken back.

pub PI = OpMathPiFloat() as float

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

pub E = OpMathEFloat() as float

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

pub fn cos(self: f64) -> f64

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

pub fn sin(self: f64) -> f64

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

pub fn tan(self: f64) -> f64

Tangent. Use for slopes and perspective projection.

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

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

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

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

pub fn atan(self: f64) -> f64

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

pub fn ceil(self: f64) -> f64

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

pub fn floor(self: f64) -> f64

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

pub fn round(self: f64) -> f64

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

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

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

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

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: f64, v2: f64) -> f64?

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: f64, v2: f64) -> f64?

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.