luz-math¶
Mathematical library included with Luz. No installation needed.
Constants¶
| Name | Value |
|---|---|
PI |
3.14159265358979 |
TAU |
6.28318530717959 |
E |
2.71828182845905 |
Number theory¶
factorial(n)¶
Returns n!. Raises an error if n < 0.
fibonacci(n)¶
Returns the nth Fibonacci number (0-indexed).
gcd(a, b)¶
Greatest common divisor.
lcm(a, b)¶
Least common multiple.
is_prime(n)¶
Returns true if n is prime.
Trigonometry¶
All functions work in radians. Use to_rad / to_deg to convert.
sin(x) / cos(x) / tan(x)¶
to_rad(degrees) / to_deg(radians)¶
Logarithms¶
log(x) — natural logarithm (base e)¶
log2(x) — base-2 logarithm¶
log10(x) — base-10 logarithm¶
Geometry¶
hypot(a, b)¶
Returns the hypotenuse of a right triangle with legs a and b.
distance(x1, y1, x2, y2)¶
Returns the Euclidean distance between two points.
cbrt(x)¶
Returns the cube root of x. Works with negative values.
lerp(a, b, t)¶
Linear interpolation between a and b by factor t (0.0–1.0).
map_range(x, in_min, in_max, out_min, out_max)¶
Maps a value from one range to another.