Library

std/math

Basic numeric operations and constants.

1 file lib/std/math/math.vader 26 exports

Functions

sqrt :: fn(x: f64) -> f64

Square root.

Parameters

xf64 non-negative finite input.

Returns

f64 sqrt(x). NaN when x < 0.
pow :: fn(x: f64, n: f64) -> f64

Power: x^n. Both base and exponent are floats ; for integer exponents the caller is expected to cast.

Parameters

xf64 base.
nf64 exponent.

Returns

f64 x raised to the n-th power.
floor :: fn(x: f64) -> f64

Largest integer n such that n <= x. floor(-1.2) → -2.0.

Parameters

xf64 No description.

Returns

f64
ceil :: fn(x: f64) -> f64

Smallest integer n such that n >= x. ceil(-1.2) → -1.0.

Parameters

xf64 No description.

Returns

f64
round :: fn(x: f64) -> f64

Round to the nearest integer, ties away from zero. round(0.5) → 1.0.

Parameters

xf64 No description.

Returns

f64
sin :: fn(x: f64) -> f64

Sine of x in radians.

Parameters

xf64 No description.

Returns

f64
cos :: fn(x: f64) -> f64

Cosine of x in radians.

Parameters

xf64 No description.

Returns

f64
tan :: fn(x: f64) -> f64

Tangent of x in radians.

Parameters

xf64 No description.

Returns

f64

min

fn 4 overloads
min :: fn(a: f64, b: f64) -> f64

Smaller of two f64s. min(NaN, x) == NaN (NaN propagates).

Parameters

af64 No description.
bf64 No description.

Returns

f64
min :: fn(a: f32, b: f32) -> f32

Smaller of two f32s. min(NaN, x) == NaN (NaN propagates).

Parameters

af32 No description.
bf32 No description.

Returns

f32
min :: fn(a: i32, b: i32) -> i32

Smaller of two i32s.

Parameters

ai32 No description.
bi32 No description.

Returns

i32
min :: fn(a: i64, b: i64) -> i64

Smaller of two i64s.

Parameters

ai64 No description.
bi64 No description.

Returns

i64

max

fn 4 overloads
max :: fn(a: f64, b: f64) -> f64

Larger of two f64s. max(NaN, x) == NaN.

Parameters

af64 No description.
bf64 No description.

Returns

f64
max :: fn(a: f32, b: f32) -> f32

Larger of two f32s. max(NaN, x) == NaN.

Parameters

af32 No description.
bf32 No description.

Returns

f32
max :: fn(a: i32, b: i32) -> i32

Larger of two i32s.

Parameters

ai32 No description.
bi32 No description.

Returns

i32
max :: fn(a: i64, b: i64) -> i64

Larger of two i64s.

Parameters

ai64 No description.
bi64 No description.

Returns

i64

abs

fn 3 overloads
abs :: fn(x: f64) -> f64

Absolute value of an f64. Preserves the sign of zero (abs(-0.0) → -0.0): caller normalises if needed.

Parameters

xf64 No description.

Returns

f64
abs :: fn(x: i32) -> i32

Absolute value of an i32. abs(i32::MIN) overflows (panics in debug, wraps in release).

Parameters

xi32 No description.

Returns

i32
abs :: fn(x: i64) -> i64

Absolute value of an i64. Same overflow caveat at i64::MIN.

Parameters

xi64 No description.

Returns

i64

clamp

fn 4 overloads
clamp :: fn(x: f64, lo: f64, hi: f64) -> f64

Clamp x to [lo, hi]. Equivalent to min(max(x, lo), hi). Behaviour when lo > hi matches the underlying calls: lo wins.

Parameters

xf64 No description.
lof64 No description.
hif64 No description.

Returns

f64
clamp :: fn(x: f32, lo: f32, hi: f32) -> f32

Clamp an f32 to [lo, hi].

Parameters

xf32 No description.
lof32 No description.
hif32 No description.

Returns

f32
clamp :: fn(x: i32, lo: i32, hi: i32) -> i32

Clamp an i32 to [lo, hi].

Parameters

xi32 No description.
loi32 No description.
hii32 No description.

Returns

i32
clamp :: fn(x: i64, lo: i64, hi: i64) -> i64

Clamp an i64 to [lo, hi].

Parameters

xi64 No description.
loi64 No description.
hii64 No description.

Returns

i64
lerp :: fn(a: f64, b: f64, t: f64) -> f64

Linear interpolation between a (t = 0) and b (t = 1). t is clamped to [0, 1] so callers don't accidentally extrapolate.

Parameters

af64 the value at t = 0.
bf64 the value at t = 1.
tf64 blend factor, clamped to [0, 1].

Returns

f64 a + (b - a) * clamp(t, 0, 1).

Constants

pi

const type inferred math.vader:6
pi: f64 :: 3.141592653589793

π (3.141592653589793).

e

const type inferred math.vader:8
e: f64 :: 2.718281828459045

Euler's number, e (2.718281828459045).

Written by vader doc. Icons: Codicons, CC BY 4.0. Fonts: Atkinson Hyperlegible, JetBrains Mono, OFL.