Lyric v4.5.0

std.math

pi binding

pub let pi: float = 3.141592653589793

The circle constant π.

stdlib/std/math.lyr:14

e binding

pub let e: float = 2.718281828459045

Euler's number, the base of the natural logarithm.

stdlib/std/math.lyr:17

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:20

abs function

pub fn abs(value: float): float

The absolute value.

stdlib/std/math.lyr:22

floor function

pub fn floor(value: float): float

Rounds down, towards negative infinity.

stdlib/std/math.lyr:27

ceil function

pub fn ceil(value: float): float

Rounds up, towards positive infinity.

stdlib/std/math.lyr:29

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:32

min function

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

The smaller of the two.

stdlib/std/math.lyr:35

max function

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

The larger of the two.

stdlib/std/math.lyr:37

pow function

pub fn pow(base: float, exponent: float): float

base raised to exponent.

stdlib/std/math.lyr:39

sin function

pub fn sin(radians: float): float

The sine of an angle in radians.

stdlib/std/math.lyr:42

cos function

pub fn cos(radians: float): float

The cosine of an angle in radians.

stdlib/std/math.lyr:44

tan function

pub fn tan(radians: float): float

The tangent of an angle in radians.

stdlib/std/math.lyr:46

log function

pub fn log(value: float): float

The natural logarithm; logBase covers every other base.

stdlib/std/math.lyr:50

asin function

pub fn asin(value: float): float

The inverse sine, in radians. Outside [-1, 1] the result is NaN.

stdlib/std/math.lyr:59

acos function

pub fn acos(value: float): float

The inverse cosine, in radians. Outside [-1, 1] the result is NaN.

stdlib/std/math.lyr:61

atan function

pub fn atan(value: float): float

The inverse tangent, in radians.

stdlib/std/math.lyr:63

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:65

tau binding

pub let tau: float = 6.283185307179586

The full turn: 2π.

stdlib/std/math.lyr:70

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:79

minInt function

pub fn minInt(a: int, b: int): int

The smaller of the two.

stdlib/std/math.lyr:84

maxInt function

pub fn maxInt(a: int, b: int): int

The larger of the two.

stdlib/std/math.lyr:89

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:94

signInt function

pub fn signInt(value: int): int

-1, 0 or 1, matching the sign.

stdlib/std/math.lyr:102

gcd function

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

Greatest common divisor, Euclidean. Always non-negative.

stdlib/std/math.lyr:110

lcm function

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

Least common multiple. lcm(0, n) is 0.

stdlib/std/math.lyr:122

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:134

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:157

modFloor function

pub fn modFloor(a: int, b: int): int

The remainder matching divFloor, always carrying the sign of b.

stdlib/std/math.lyr:167

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:178

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:186

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:194

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:200

isInfinite function

pub fn isInfinite(value: float): bool

Whether the value is positive or negative infinity. NaN is neither.

stdlib/std/math.lyr:205

isFinite function

pub fn isFinite(value: float): bool

Whether the value is neither NaN nor infinite.

stdlib/std/math.lyr:214

exp function

pub fn exp(value: float): float

e raised to value.

stdlib/std/math.lyr:219

log2 function

pub fn log2(value: float): float

The base-2 logarithm.

stdlib/std/math.lyr:226

log10 function

pub fn log10(value: float): float

The base-10 logarithm.

stdlib/std/math.lyr:228

logBase function

pub fn logBase(value: float, base: float): float

The logarithm to an arbitrary base.

stdlib/std/math.lyr:231

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:239

hypot function

pub fn hypot(a: float, b: float): float

The length of the hypotenuse.

stdlib/std/math.lyr:247

sinh function

pub fn sinh(value: float): float

The hyperbolic sine.

stdlib/std/math.lyr:252

cosh function

pub fn cosh(value: float): float

The hyperbolic cosine.

stdlib/std/math.lyr:257

tanh function

pub fn tanh(value: float): float

The hyperbolic tangent.

stdlib/std/math.lyr:262

toRadians function

pub fn toRadians(degrees: float): float

Degrees to radians.

stdlib/std/math.lyr:267

toDegrees function

pub fn toDegrees(radians: float): float

Radians to degrees.

stdlib/std/math.lyr:272