std/float
std/float
Section titled “std/float”std/float — f32 / f64 to-string formatting. Up to 7 fractional digits for f32, 15 for f64 (matching IEEE 754 single / double precision); trailing zeros trimmed and the decimal point is dropped if the fraction is zero. NaN gets the canonical “NaN”; ±Inf get “Inf” / “-Inf”. Detection of Inf is approximate — the threshold check (n * 2.0 == n) covers every practically-encountered case but isn’t bit- exact against f64.const inf. Migrated from the auto-injected prelude per docs/PRELUDE-TO-MODULES.md.
to_string
Section titled “to_string”pub function (n: f32) to_string(): stringto_string
Section titled “to_string”pub function (n: f64) to_string(): stringpub function (x: f64) abs(): f64pub function (x: f64) floor(): f64pub function (x: f64) ceil(): f64pub function (x: f64) round(): f64round(x) follows the “round half away from zero”
convention (matches Go’s math.Round). Tests that need
banker’s rounding (round half to even) should reach
into the bit-pattern themselves.
pub function (x: f64) trunc(): f64trunc(x) is round-toward-zero, equivalent to
(x as i64) as f64 for values that fit in the i64 range.
The primitive form handles ±Inf / NaN that the cast
version would reject.
pub function (x: f64) sqrt(): f64pub function (x: f64) log(): f64pub function (x: f64) exp(): f64pub function (x: f64) sin(): f64pub function (x: f64) cos(): f64pub function (x: f64) pow(y: f64): f64pow(x, y) — two-argument form; method receiver is the
base. Use (b).pow(e) for b ^ e.
is_nan
Section titled “is_nan”pub function (x: f64) is_nan(): booleanis_nan(x) / is_inf(x) / is_finite(x) — IEEE-754
classification. The NaN predicate uses the textbook
“x != x” pattern; is_inf checks both ±Inf by squaring
(Inf * 2 == Inf, finite * 2 grows), is_finite is the
negation. Helpers so test code doesn’t have to spell out
the textbook patterns every time.
is_finite
Section titled “is_finite”pub function (x: f64) is_finite(): booleanis_inf
Section titled “is_inf”pub function (x: f64) is_inf(): booleanpub function (x: f64) min(y: f64): f64min(x, y) / max(x, y) — return the smaller / larger
value. NaN inputs are infectious (any NaN in → NaN out),
matching Go’s math.Min / math.Max semantics. Float
comparisons with NaN are well-defined as “always false”,
which is what the inline check below relies on.
pub function (x: f64) max(y: f64): f64pub function (x: f64) clamp(lo: f64, hi: f64): f64clamp(x, lo, hi) — restrict to [lo, hi]. Implemented
as max(lo, min(hi, x)); preserves NaN if any input is
NaN.
pub function (x: f32) abs(): f32pub function (x: f32) floor(): f32pub function (x: f32) ceil(): f32pub function (x: f32) round(): f32pub function (x: f32) trunc(): f32pub function (x: f32) sqrt(): f32pub function (x: f32) log(): f32pub function (x: f32) exp(): f32pub function (x: f32) sin(): f32pub function (x: f32) cos(): f32pub function (x: f32) pow(y: f32): f32is_nan
Section titled “is_nan”pub function (x: f32) is_nan(): booleanis_finite
Section titled “is_finite”pub function (x: f32) is_finite(): booleanis_inf
Section titled “is_inf”pub function (x: f32) is_inf(): booleanpub function (x: f32) min(y: f32): f32pub function (x: f32) max(y: f32): f32pub function (x: f32) clamp(lo: f32, hi: f32): f32