Skip to content

Math Module

This one is a brief module because these math functions are common in basically every programming language, so I’ll keep the explanations short and straight to the point.

math.mini

math.mini(a: i64, b: i64)

Returns the minimum of two i64 values

Arguments

ParameterType
ai64
bi64

Example

solus
assert(math.mini(-300, 20) == -300);

math.maxi

math.maxi(a: i64, b: i64)

Returns the maximum of two i64 values

Arguments

ParameterType
ai64
bi64

Example

solus
assert(math.maxi(-300, 20) == 20);

math.minf

math.minf(a: f64, b: f64)

Returns the minimum of two f64 values

Arguments

ParameterType
af64
bf64

Example

solus
assert(math.minf(-inf, inf) == -inf);

math.maxf

math.maxf(a: f64, b: f64)

Returns the maximum of two f64 values

Arguments

ParameterType
af64
bf64

Example

solus
assert(math.maxf(-inf, inf) == inf);

math.isnan

math.isnan(number: f64)

Returns true if number is f64 and nan. Otherwise, returns false. nan cannot be compared with anything but this function.

Arguments

ParameterType
numberf64

math.randi

math.randi(min_v: i64, max_v: i64)

Returns a random integer between a minimum and maximum value, inclusive

Arguments

ParameterTypeDescription
min_vi64Minimum value (inclusive)
max_vi64Maximum value (inclusive)

math.randf

math.randf(min_v: f64, max_v: f64)

Returns a random number between a minimum and maximum value, inclusive

Arguments

ParameterTypeDescription
min_vf64Minimum value (inclusive)
max_vf64Maximum value (inclusive)

math.lerp

math.lerp(a: f64, b: f64, t: f64) -> f64

Linearly interpolates between two numbers by a percentage between 0.0 and 1.0

Arguments

ParameterTypeDescription
af64Start value
bf64Target value
tf64Percentage value (0.0-1.0)

Example

solus
val start = -100f;
val end = 100f;
val time = 5f;

var counter = 0f;
var last_time = io.time();
while (counter < time) {
    io.println(math.lerp(start, end, counter/time));
    counter += io.time() - last_time;
    last_time = io.time();
}