← all modules
module

stdlib::math

defined in C:\Users\bye45\.glide\bin/src/stdlib/math.glide

Square root. Returns NaN for negative input.

fn fn sqrt(x: f64) -> f64

Square root. Returns NaN for negative input.

glide
sqrt(2.0);    // 1.4142135623730951

sqrt(9.0);    // 3.0
fn fn pow(x: f64, y: f64) -> f64

x^y as a float. For integer exponents prefer ipow to avoid floating-point drift.

glide
pow(2.0, 10.0);   // 1024.0

pow(3.0, 0.5);    // sqrt(3) = 1.7320508...
fn fn floor(x: f64) -> f64

Round toward -∞.

glide
floor(2.7);     //  2.0

floor(-2.3);    // -3.0
fn fn ceil(x: f64) -> f64

Round toward +∞.

glide
ceil(2.1);     //  3.0

ceil(-2.7);    // -2.0
fn fn round(x: f64) -> f64

Round to nearest, ties away from zero.

glide
round(2.5);     //  3.0

round(-2.5);    // -3.0

round(2.4);     //  2.0
fn fn fabs(x: f64) -> f64

Absolute value (float). Use abs_int for ints.

glide
fabs(-1.5);     // 1.5

fabs(0.0);      // 0.0
fn fn sin(x: f64) -> f64

Sine. Argument is in radians.

glide
sin(0.0);          // 0.0

sin(PI / 2.0);     // 1.0
fn fn cos(x: f64) -> f64

Cosine. Argument is in radians.

glide
cos(0.0);     // 1.0

cos(PI);      // -1.0
fn fn tan(x: f64) -> f64

Tangent. Argument is in radians.

glide
tan(PI / 4.0);   // 1.0
fn fn log(x: f64) -> f64

Natural log (base e). Domain x > 0.

glide
log(E);         // 1.0

log(1.0);       // 0.0
fn fn log2(x: f64) -> f64

Log base 2.

glide
log2(8.0);      // 3.0

log2(1024.0);   // 10.0
fn fn log10(x: f64) -> f64

Log base 10.

glide
log10(1000.0);   // 3.0

log10(1.0);      // 0.0
fn fn exp(x: f64) -> f64

e^x.

glide
exp(0.0);    // 1.0

exp(1.0);    // E (≈ 2.71828)
fn fn atan2(y: f64, x: f64) -> f64

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.

glide
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)
const const PI: f64
const const E: f64
fn fn min_int(a: int, b: int) -> int

Smaller of two ints.

glide
let a: int = min_int(7, 3);   // 3
fn fn max_int(a: int, b: int) -> int

Larger of two ints.

glide
let a: int = max_int(7, 3);   // 7
fn fn abs_int(a: int) -> int

Absolute value for ints. Note: abs_int(INT_MIN) overflows on two's-complement platforms; callers handling user input should clamp.

glide
abs_int(-5);   // 5

abs_int(0);    // 0
fn fn sign_int(a: int) -> int

Sign of an int: -1, 0, or +1.

glide
sign_int(-9);  // -1

sign_int(0);   //  0

sign_int(42);  //  1
fn fn clamp_int(x: int, lo: int, hi: int) -> int

Clamp x into the inclusive range [lo, hi]. Behaviour is undefined when lo > hi; the caller is expected to keep the range well-formed.

glide
clamp_int(15, 0, 10);   // 10

clamp_int(-3, 0, 10);   //  0

clamp_int(5,  0, 10);   //  5
fn fn min_f64(a: f64, b: f64) -> f64

Smaller of two f64s. NaN behaviour follows libc semantics (an operand of NaN propagates).

glide
min_f64(1.5, 2.5);   // 1.5
fn fn max_f64(a: f64, b: f64) -> f64

Larger of two f64s.

glide
max_f64(1.5, 2.5);   // 2.5
fn fn clamp_f64(x: f64, lo: f64, hi: f64) -> f64

f64 clamp into [lo, hi]. See clamp_int for caveats.

glide
clamp_f64(0.5, 0.0, 1.0);   // 0.5

clamp_f64(2.0, 0.0, 1.0);   // 1.0
fn fn ipow(a: int, b: int) -> int

Integer pow: a^b for non-negative b, computed by repeated squaring in O(log b). Wraps on overflow following two's-complement.

glide
ipow(2, 10);   // 1024

ipow(3, 4);    // 81

ipow(5, 0);    // 1   (any^0)
fn fn gcd(a: int, b: int) -> int

Greatest common divisor via Euclidean algorithm. Always returns a non-negative value: gcd(0, 0) == 0, gcd(-12, 8) == 4.

glide
gcd(12, 18);   // 6

gcd(100, 75);  // 25
fn fn lcm(a: int, b: int) -> int

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.

glide
lcm(4, 6);    // 12

lcm(15, 20);  // 60