math/core

sourcemath/core.sx

abs_i64

pub fn abs_i64(x: i64) i64

Absolute value of a 64-bit signed integer.

min_i64

pub fn min_i64(a: i64, b: i64) i64

Minimum of two i64 values.

max_i64

pub fn max_i64(a: i64, b: i64) i64

Maximum of two i64 values.

clamp_i64

pub fn clamp_i64(x: i64, lo: i64, hi: i64) i64

Clamp `x` to [lo, hi].

sign_i64

pub fn sign_i64(x: i64) i64

Sign of an i64: returns -1, 0, or 1.

rem

pub fn rem(a: i64, b: i64) i64

abs

pub fn abs(x: i64) i64

Absolute value

min

pub fn min(a: i64, b: i64) i64

Min / Max

max

pub fn max(a: i64, b: i64) i64

clamp

pub fn clamp(x: i64, lo: i64, hi: i64) i64

Clamp value into [lo, hi]

pow

pub fn pow(base: i64, exp: usize) i64

Power (integer, simple loop)

gcd

pub fn gcd(a: i64, b: i64) i64

Greatest Common Divisor (Euclidean)

lcm

pub fn lcm(a: i64, b: i64) i64

Least Common Multiple

fmin

pub fn fmin(a: f64, b: f64) f64

fmax

pub fn fmax(a: f64, b: f64) f64

fabs

pub fn fabs(x: f64) f64

fclamp

pub fn fclamp(x: f64, lo: f64, hi: f64) f64

floor

pub fn floor(x: f64) f64

ceil

pub fn ceil(x: f64) f64

trunc

pub fn trunc(x: f64) f64

fract

pub fn fract(x: f64) f64

sqrt

pub fn sqrt(x: f64) f64

Square root using Newton's method

fpow

pub fn fpow(base: f64, exp: usize) f64

lerp

pub fn lerp(a: f64, b: f64, t: f64) f64

Linear interpolation

clamp01

pub fn clamp01(x: f64) f64

Clamp a normalized scalar into [0, 1].

inverse_lerp

pub fn inverse_lerp(a: f64, b: f64, value: f64) f64

Compute the interpolation factor of `value` between `a` and `b`.

remap

pub fn remap(value: f64, in_lo: f64, in_hi: f64, out_lo: f64, out_hi: f64) f64

Map a value from one range to another.

normalize_radians

pub fn normalize_radians(angle: f64) f64

Wrap radians into the half-open range [0, TAU).

normalize_degrees

pub fn normalize_degrees(angle: f64) f64

Wrap degrees into the half-open range [0, 360).

shortest_angle_delta

pub fn shortest_angle_delta(from: f64, to: f64) f64

Return the shortest signed angular difference from `from` to `to`, in radians.

is_even

pub fn is_even(x: i64) bool

Is this number even?

is_odd

pub fn is_odd(x: i64) bool

Is this number odd?

approx_eq

pub fn approx_eq(a: f64, b: f64, eps: f64) bool

Check approximate equality

exp

pub fn exp(x: f64) f64

Exponential function (e^x) using Taylor series

logarithm

pub fn logarithm(x: f64) f64

Natural logarithm (ln(x)) using Newton's method

log10

pub fn log10(x: f64) f64

Base-10 logarithm

log2

pub fn log2(x: f64) f64

Base-2 logarithm

sin

pub fn sin(x: f64) f64

Sine function using Taylor series

cos

pub fn cos(x: f64) f64

Cosine function

tan

pub fn tan(x: f64) f64

Tangent function

asin

pub fn asin(x: f64) f64

Arcsine (inverse sine) using Newton's method

acos

pub fn acos(x: f64) f64

Arccosine (inverse cosine)

atan

pub fn atan(x: f64) f64

Arctangent (inverse tangent) using series expansion

atan2

pub fn atan2(y: f64, x: f64) f64

Two-argument arctangent (atan2)

sinh

pub fn sinh(x: f64) f64

Hyperbolic sine

cosh

pub fn cosh(x: f64) f64

Hyperbolic cosine

tanh

pub fn tanh(x: f64) f64

Hyperbolic tangent

to_radians

pub fn to_radians(degrees: f64) f64

Convert degrees to radians

to_degrees

pub fn to_degrees(radians: f64) f64

Convert radians to degrees

round

pub fn round(x: f64) f64

Round to nearest integer

pow_f64

pub fn pow_f64(base: f64, exponent: f64) f64

Compute x^y for floating point

cbrt

pub fn cbrt(x: f64) f64

Cube root

hypot

pub fn hypot(x: f64, y: f64) f64

Hypotenuse (sqrt(x^2 + y^2))

copysign

pub fn copysign(mag: f64, sign: f64) f64

Copy sign from one number to another

fma

pub fn fma(a: f64, b: f64, c: f64) f64

Fused multiply-add: (a * b) + c