mirror of
https://github.com/bearlanguageorg/bear.git
synced 2026-08-26 16:07:01 +00:00
62 lines
614 B
Plaintext
62 lines
614 B
Plaintext
// math.vr — math helpers (part of the VuurRaaf stdlib).
|
|
//
|
|
// import math
|
|
// println(math.clamp(150, 0, 100))
|
|
// println(math.sign(-3))
|
|
|
|
fn abs(x) {
|
|
return abs(x)
|
|
}
|
|
|
|
fn min(a, b) {
|
|
return min(a, b)
|
|
}
|
|
|
|
fn max(a, b) {
|
|
return max(a, b)
|
|
}
|
|
|
|
fn floor(x) {
|
|
return floor(x)
|
|
}
|
|
|
|
fn ceil(x) {
|
|
return ceil(x)
|
|
}
|
|
|
|
fn round(x) {
|
|
return round(x)
|
|
}
|
|
|
|
fn sqrt(x) {
|
|
return sqrt(x)
|
|
}
|
|
|
|
fn pow(a, b) {
|
|
return pow(a, b)
|
|
}
|
|
|
|
fn clamp(x, lo, hi) {
|
|
if x < lo {
|
|
return lo
|
|
}
|
|
if x > hi {
|
|
return hi
|
|
}
|
|
return x
|
|
}
|
|
|
|
fn sign(x) {
|
|
if x < 0 {
|
|
return -1
|
|
}
|
|
if x > 0 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
fn pi() {
|
|
return 3.14159
|
|
}
|