std.math
pi binding
pub let pi: float = 3.141592653589793
The circle constant π.
stdlib/std/math.lyr:16
e binding
pub let e: float = 2.718281828459045
Euler's number, the base of the natural logarithm.
stdlib/std/math.lyr:19
sqrt function
pub fn sqrt(value: float): float
The square root. A negative value yields NaN (IEEE 754), not a panic.
stdlib/std/math.lyr:22
abs function
pub fn abs(value: float): float
The absolute value.
stdlib/std/math.lyr:24
floor function
pub fn floor(value: float): float
Rounds down, towards negative infinity.
stdlib/std/math.lyr:29
ceil function
pub fn ceil(value: float): float
Rounds up, towards positive infinity.
stdlib/std/math.lyr:31
round function
pub fn round(value: float): float
Rounds to the nearest whole number; a .5 goes to the EVEN neighbour (IEEE 754), which avoids the bias of always rounding up.
stdlib/std/math.lyr:34
min function
pub fn min(a: float, b: float): float
The smaller of the two.
stdlib/std/math.lyr:37
max function
pub fn max(a: float, b: float): float
The larger of the two.
stdlib/std/math.lyr:39
pow function
pub fn pow(base: float, exponent: float): float
base raised to exponent.
stdlib/std/math.lyr:41
sin function
pub fn sin(radians: float): float
The sine of an angle in radians.
stdlib/std/math.lyr:44
cos function
pub fn cos(radians: float): float
The cosine of an angle in radians.
stdlib/std/math.lyr:46
tan function
pub fn tan(radians: float): float
The tangent of an angle in radians.
stdlib/std/math.lyr:48
log function
pub fn log(value: float): float
The natural logarithm; logBase covers every other base.
stdlib/std/math.lyr:52
asin function
pub fn asin(value: float): float
The inverse sine, in radians. Outside [-1, 1] the result is NaN.
stdlib/std/math.lyr:61
acos function
pub fn acos(value: float): float
The inverse cosine, in radians. Outside [-1, 1] the result is NaN.
stdlib/std/math.lyr:63
atan function
pub fn atan(value: float): float
The inverse tangent, in radians.
stdlib/std/math.lyr:65
atan2 function
pub fn atan2(y: float, x: float): float
The angle of the point (x, y) in radians — the quadrant-aware inverse tangent.
stdlib/std/math.lyr:67
tau binding
pub let tau: float = 6.283185307179586
The full turn: 2π.
stdlib/std/math.lyr:72
absInt function
pub fn absInt(value: int): int
The absolute value. The most negative int has no positive twin and comes back
unchanged — arithmetic wraps.
stdlib/std/math.lyr:81
minInt function
pub fn minInt(a: int, b: int): int
The smaller of the two.
stdlib/std/math.lyr:86
maxInt function
pub fn maxInt(a: int, b: int): int
The larger of the two.
stdlib/std/math.lyr:91
clampInt function
pub fn clampInt(value: int, lo: int, hi: int): int
Clamps to [lo, hi]. A lo > hi yields lo; the bounds are the caller's business.
stdlib/std/math.lyr:96
signInt function
pub fn signInt(value: int): int
-1, 0 or 1, matching the sign.
stdlib/std/math.lyr:104
gcd function
pub fn gcd(a: int, b: int): int
Greatest common divisor, Euclidean. Always non-negative.
stdlib/std/math.lyr:112
lcm function
pub fn lcm(a: int, b: int): int
Least common multiple. lcm(0, n) is 0.
stdlib/std/math.lyr:124
powInt function
pub fn powInt(base: int, exponent: int): ?int
Integer power by repeated squaring.
A negative exponent yields null: the result would be a fraction.
stdlib/std/math.lyr:136
divFloor function
pub fn divFloor(a: int, b: int): int
Division rounding towards negative infinity rather than towards zero.
/ and % follow the sign of the dividend, so -7 / 2 is -3.
Computing on a grid (tiles, time windows) needs -4. Both forms stand side by side so the
choice is visible.
stdlib/std/math.lyr:159
modFloor function
pub fn modFloor(a: int, b: int): int
The remainder matching divFloor, always carrying the sign of b.
stdlib/std/math.lyr:169
clamp function
pub fn clamp(value: float, lo: float, hi: float): float
Clamps to [lo, hi]. A lo > hi yields lo; the bounds are the caller's business.
stdlib/std/math.lyr:180
sign function
pub fn sign(value: float): float
-1.0, 0.0 or 1.0, matching the sign. NaN yields 0.0.
stdlib/std/math.lyr:188
trunc function
pub fn trunc(value: float): float
Truncates towards zero: trunc(-2.7) is -2.0, while floor(-2.7) would be -3.0.
stdlib/std/math.lyr:196
isNaN function
pub fn isNaN(value: float): bool
NaN is the only value unequal to itself (IEEE 754), so this needs no native edge and no bit
access.
stdlib/std/math.lyr:202
isInfinite function
pub fn isInfinite(value: float): bool
Whether the value is positive or negative infinity. NaN is neither.
stdlib/std/math.lyr:207
isFinite function
pub fn isFinite(value: float): bool
Whether the value is neither NaN nor infinite.
stdlib/std/math.lyr:216
exp function
pub fn exp(value: float): float
e raised to value.
stdlib/std/math.lyr:221
log2 function
pub fn log2(value: float): float
The base-2 logarithm.
stdlib/std/math.lyr:228
log10 function
pub fn log10(value: float): float
The base-10 logarithm.
stdlib/std/math.lyr:230
logBase function
pub fn logBase(value: float, base: float): float
The logarithm to an arbitrary base.
stdlib/std/math.lyr:233
cbrt function
pub fn cbrt(value: float): float
The cube root, negative values included.
pow(x, 1/3) alone yields NaN for negative x: a fractional power is undefined there. The
cube root is not, and the sign simply moves out.
stdlib/std/math.lyr:241
hypot function
pub fn hypot(a: float, b: float): float
The length of the hypotenuse.
stdlib/std/math.lyr:249
sinh function
pub fn sinh(value: float): float
The hyperbolic sine.
stdlib/std/math.lyr:254
cosh function
pub fn cosh(value: float): float
The hyperbolic cosine.
stdlib/std/math.lyr:259
tanh function
pub fn tanh(value: float): float
The hyperbolic tangent.
stdlib/std/math.lyr:264
toRadians function
pub fn toRadians(degrees: float): float
Degrees to radians.
stdlib/std/math.lyr:269
toDegrees function
pub fn toDegrees(radians: float): float
Radians to degrees.
stdlib/std/math.lyr:274
Random class
pub class Random
A deterministic pseudo-random generator (xorshift64*): one int of state, seeded by the
caller. Not cryptographic — keys need a source from the operating system.
state: int
The generator state; every draw replaces it.
pub mut fn nextInt(): int
The next raw value. It may have either sign.
pub mut fn nextIntRange(lo: int, hi: int): int
Uniformly distributed in [lo, hi). An empty range yields lo.
pub mut fn nextFloat(): float
Uniformly distributed in [0, 1).
pub static fn seeded(seed: int): Random
A generator with an explicit seed. A seed of 0 is a fixed point for xorshift — the sequence would stay 0 forever — so it is replaced silently rather than panicking on a plausible input.
pub mut fn nextBool(): bool
True or false, from the next draw's parity.
stdlib/std/math.lyr:291
newRandom function
pub fn newRandom(seed: int): Random
A generator with an explicit seed.
stdlib/std/math.lyr:335