Square root. Returns NaN for negative input.
sqrt(2.0); // 1.4142135623730951
sqrt(9.0); // 3.0
defined in C:\Users\bye45\.glide\bin/src/stdlib/math.glide
Square root. Returns NaN for negative input.
Square root. Returns NaN for negative input.
sqrt(2.0); // 1.4142135623730951
sqrt(9.0); // 3.0
x^y as a float. For integer exponents prefer ipow to avoid floating-point drift.
pow(2.0, 10.0); // 1024.0
pow(3.0, 0.5); // sqrt(3) = 1.7320508...
Round toward -∞.
floor(2.7); // 2.0
floor(-2.3); // -3.0
Round toward +∞.
ceil(2.1); // 3.0
ceil(-2.7); // -2.0
Round to nearest, ties away from zero.
round(2.5); // 3.0
round(-2.5); // -3.0
round(2.4); // 2.0
Absolute value (float). Use abs_int for ints.
fabs(-1.5); // 1.5
fabs(0.0); // 0.0
Sine. Argument is in radians.
sin(0.0); // 0.0
sin(PI / 2.0); // 1.0
Cosine. Argument is in radians.
cos(0.0); // 1.0
cos(PI); // -1.0
Tangent. Argument is in radians.
tan(PI / 4.0); // 1.0
Natural log (base e). Domain x > 0.
log(E); // 1.0
log(1.0); // 0.0
Log base 2.
log2(8.0); // 3.0
log2(1024.0); // 10.0
Log base 10.
log10(1000.0); // 3.0
log10(1.0); // 0.0
e^x.
exp(0.0); // 1.0
exp(1.0); // E (≈ 2.71828)
Two-argument arctangent: full-circle angle of point (x, y) in radians. Use this instead of atan(y / x) when you need the right quadrant.
atan2(1.0, 0.0); // PI / 2 (point straight up)
atan2(0.0, 1.0); // 0 (point along +X)
atan2(0.0, -1.0); // PI (point along -X)
Smaller of two ints.
let a: int = min_int(7, 3); // 3
Larger of two ints.
let a: int = max_int(7, 3); // 7
Absolute value for ints. Note: abs_int(INT_MIN) overflows on two's-complement platforms; callers handling user input should clamp.
abs_int(-5); // 5
abs_int(0); // 0
Sign of an int: -1, 0, or +1.
sign_int(-9); // -1
sign_int(0); // 0
sign_int(42); // 1
Clamp x into the inclusive range [lo, hi]. Behaviour is undefined when lo > hi; the caller is expected to keep the range well-formed.
clamp_int(15, 0, 10); // 10
clamp_int(-3, 0, 10); // 0
clamp_int(5, 0, 10); // 5
Smaller of two f64s. NaN behaviour follows libc semantics (an operand of NaN propagates).
min_f64(1.5, 2.5); // 1.5
Larger of two f64s.
max_f64(1.5, 2.5); // 2.5
f64 clamp into [lo, hi]. See clamp_int for caveats.
clamp_f64(0.5, 0.0, 1.0); // 0.5
clamp_f64(2.0, 0.0, 1.0); // 1.0
Integer pow: a^b for non-negative b, computed by repeated squaring in O(log b). Wraps on overflow following two's-complement.
ipow(2, 10); // 1024
ipow(3, 4); // 81
ipow(5, 0); // 1 (any^0)
Greatest common divisor via Euclidean algorithm. Always returns a non-negative value: gcd(0, 0) == 0, gcd(-12, 8) == 4.
gcd(12, 18); // 6
gcd(100, 75); // 25
Least common multiple. Returns 0 when either argument is 0. Computed as |a / gcd(a,b) * b| to reduce overflow risk on the intermediate product.
lcm(4, 6); // 12
lcm(15, 20); // 60