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
| Parameter | Type |
|---|---|
a | i64 |
b | i64 |
Example
solus
assert(math.mini(-300, 20) == -300);math.maxi
math.maxi(a: i64, b: i64)
Returns the maximum of two i64 values
Arguments
| Parameter | Type |
|---|---|
a | i64 |
b | i64 |
Example
solus
assert(math.maxi(-300, 20) == 20);math.minf
math.minf(a: f64, b: f64)
Returns the minimum of two f64 values
Arguments
| Parameter | Type |
|---|---|
a | f64 |
b | f64 |
Example
solus
assert(math.minf(-inf, inf) == -inf);math.maxf
math.maxf(a: f64, b: f64)
Returns the maximum of two f64 values
Arguments
| Parameter | Type |
|---|---|
a | f64 |
b | f64 |
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
| Parameter | Type |
|---|---|
number | f64 |
math.randi
math.randi(min_v: i64, max_v: i64)
Returns a random integer between a minimum and maximum value, inclusive
Arguments
| Parameter | Type | Description |
|---|---|---|
min_v | i64 | Minimum value (inclusive) |
max_v | i64 | Maximum value (inclusive) |
math.randf
math.randf(min_v: f64, max_v: f64)
Returns a random number between a minimum and maximum value, inclusive
Arguments
| Parameter | Type | Description |
|---|---|---|
min_v | f64 | Minimum value (inclusive) |
max_v | f64 | Maximum 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
| Parameter | Type | Description |
|---|---|---|
a | f64 | Start value |
b | f64 | Target value |
t | f64 | Percentage 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();
}