num
Numbers: constants, math, tests, integer ranges, and conversion to and from text, the same in every locale.
Except for the documented rounding and clamp rules, operations follow ECMAScript
numeric special cases, with Saka’s canonical zero and nan. Angles use radians.
Transcendental approximations need not be bit-identical across engines.
lin functions run once for each combination of their arguments’ Values.
Write these names after num::, as in num::min_safe_int.
min_safe_int
def min_safe_intSmallest integer whose neighboring integers remain exactly representable.
max_safe_int
def max_safe_intLargest integer whose neighboring integers remain exactly representable.
epsilon
def epsilonThe gap between one and the next larger number; not a universal comparison tolerance.
pi
def piThe binary64 approximation of the ratio of a circle’s circumference to its diameter.
e
def eThe binary64 approximation of the base of natural logarithms.
is_finite
def lin is_finite(value: num): boolTrue for numbers other than infinities and nan.
is_int
def lin is_int(value: num): boolTrue for finite integral numbers, including integers outside the safe range.
is_safe_int
def lin is_safe_int(value: num): boolTrue for finite integers in the inclusive min_safe_int–max_safe_int range.
abs
def lin abs(value: num): numAbsolute value; preserves infinity and nan.
sign
def lin sign(value: num): numReturns -1, 0, or 1 according to the sign; returns nan for nan.
floor
def lin floor(value: num): numRounds toward negative infinity; preserves infinities and nan.
ceil
def lin ceil(value: num): numRounds toward positive infinity; preserves infinities and nan.
trunc
def lin trunc(value: num): numDiscards the fractional part toward zero; preserves infinities and nan.
round
def lin round(value: num): numRounds to the nearest integer, choosing the even integer at a tie.
Preserves infinities and nan; for example, both 1.5 and 2.5 round to 2.
sqrt
def lin sqrt(value: num): numSquare root; negative inputs produce nan.
exp
def lin exp(value: num): numNatural exponential, e raised to the input power.
ln
def lin ln(value: num): numNatural logarithm; zero produces negative infinity and negative inputs produce nan.
log2
def lin log2(value: num): numBase-two logarithm; zero produces negative infinity and negative inputs produce nan.
log10
def lin log10(value: num): numBase-ten logarithm; zero produces negative infinity and negative inputs produce nan.
sin
def lin sin(value: num): numSine of an angle in radians.
cos
def lin cos(value: num): numCosine of an angle in radians.
tan
def lin tan(value: num): numTangent of an angle in radians.
asin
def lin asin(value: num): numInverse sine in radians; inputs outside [-1, 1] produce nan.
acos
def lin acos(value: num): numInverse cosine in radians; inputs outside [-1, 1] produce nan.
atan
def lin atan(value: num): numInverse tangent in radians.
pow
def lin pow(base: num, exponent: num): numRaises base to exponent, using ECMAScript exponentiation special cases.
atan2
def lin atan2(y: num, x: num): numAngle in radians of the point (x, y), with the quadrant selected from both signs.
clamp
def lin clamp(value: num, lower: num, upper: num): numRestricts a value to inclusive bounds. Any nan argument produces nan.
Otherwise reversed bounds fail with Conflict; equal bounds are allowed.
range
def range(start! num, end! num)* numReturns each integer from start up to but excluding end once; end <= start returns an empty Bag.
Non-safe-integer bounds and ranges larger than the Bag-total limit fail with Conflict.
Bags are unordered, so use each value as its own key where order matters: num::range(0, n) map i => i -> ….
parse
def lin parse(text: str): numParses a complete signed decimal/scientific spelling, or exactly nan, inf, or -inf.
Accepts .5, 1., and exponents; at least one mantissa digit is required.
Whitespace, separators, radix prefixes, empty input, and trailing text return nan.
Conversion rounds to binary64, allows overflow to infinity, and canonicalizes negative zero.
format
def lin format(value: num): strReturns the shortest round-trippable ECMAScript finite-number spelling, without locale rules.
Special values use nan, inf, -inf, and 0. Parsing the result reproduces the input.
format_fixed
def lin format_fixed(value: num, digits: num): strFormats with 0–100 digits after the decimal point using ECMAScript fixed formatting.
This rounding follows decimal string formatting, not num::round ties-to-even arithmetic.
format_scientific
def lin format_scientific(value: num, digits: num): strFormats with 0–100 digits after the decimal point in scientific notation.
format_precision
def lin format_precision(value: num, digits: num): strFormats with 1–100 significant digits using ECMAScript precision formatting.