Skip to content
Open Saka

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_int

Smallest integer whose neighboring integers remain exactly representable.

max_safe_int

def max_safe_int

Largest integer whose neighboring integers remain exactly representable.

epsilon

def epsilon

The gap between one and the next larger number; not a universal comparison tolerance.

pi

def pi

The binary64 approximation of the ratio of a circle’s circumference to its diameter.

e

def e

The binary64 approximation of the base of natural logarithms.

is_finite

def lin is_finite(value: num): bool

True for numbers other than infinities and nan.

is_int

def lin is_int(value: num): bool

True for finite integral numbers, including integers outside the safe range.

is_safe_int

def lin is_safe_int(value: num): bool

True for finite integers in the inclusive min_safe_int–max_safe_int range.

abs

def lin abs(value: num): num

Absolute value; preserves infinity and nan.

sign

def lin sign(value: num): num

Returns -1, 0, or 1 according to the sign; returns nan for nan.

floor

def lin floor(value: num): num

Rounds toward negative infinity; preserves infinities and nan.

ceil

def lin ceil(value: num): num

Rounds toward positive infinity; preserves infinities and nan.

trunc

def lin trunc(value: num): num

Discards the fractional part toward zero; preserves infinities and nan.

round

def lin round(value: num): num

Rounds 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): num

Square root; negative inputs produce nan.

exp

def lin exp(value: num): num

Natural exponential, e raised to the input power.

ln

def lin ln(value: num): num

Natural logarithm; zero produces negative infinity and negative inputs produce nan.

log2

def lin log2(value: num): num

Base-two logarithm; zero produces negative infinity and negative inputs produce nan.

log10

def lin log10(value: num): num

Base-ten logarithm; zero produces negative infinity and negative inputs produce nan.

sin

def lin sin(value: num): num

Sine of an angle in radians.

cos

def lin cos(value: num): num

Cosine of an angle in radians.

tan

def lin tan(value: num): num

Tangent of an angle in radians.

asin

def lin asin(value: num): num

Inverse sine in radians; inputs outside [-1, 1] produce nan.

acos

def lin acos(value: num): num

Inverse cosine in radians; inputs outside [-1, 1] produce nan.

atan

def lin atan(value: num): num

Inverse tangent in radians.

pow

def lin pow(base: num, exponent: num): num

Raises base to exponent, using ECMAScript exponentiation special cases.

atan2

def lin atan2(y: num, x: num): num

Angle in radians of the point (x, y), with the quadrant selected from both signs.

clamp

def lin clamp(value: num, lower: num, upper: num): num

Restricts 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)* num

Returns 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): num

Parses 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): str

Returns 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): str

Formats 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): str

Formats with 0–100 digits after the decimal point in scientific notation.

format_precision

def lin format_precision(value: num, digits: num): str

Formats with 1–100 significant digits using ECMAScript precision formatting.