Expand description
Round-number selector nodes.
General-purpose “snap this magnitude to a nice round number” math on
f64 values. Four scale families — powers of ten (base10), multiples
of the base-ten magnitude (decade), Fibonacci numbers (fibonacci),
and powers of two (binomial) — each in floor_ / ceiling_ /
closest_ variants, plus a general arbitrary-interval rounder.
These are pure numeric utilities (no adapter, no prefix), used to pick human-friendly axis ticks, bucket boundaries, and magnitude labels.
Edge handling: every family selector returns 0.0 for x <= 0 and for
non-finite x — no panics, no NaN/inf leaking. Fractional x in (0,1)
yields fractional powers for base10/binomial (e.g. floor_base10(0.5) = 0.1), which is correct and preserved. The interval rounders return
x unchanged when interval is non-positive or non-finite (identity —
never divide by zero).
Structs§
- Ceiling
Base10 - Smallest power of ten
>= x:10^ceil(log10(x)).x <= 0→0.0. - Ceiling
Binomial - Smallest power of two
>= x:2^ceil(log2(x)).x <= 0→0.0. - Ceiling
Decade - Round
xup to a multiple of its base-ten magnitude:ceil(x/base)*base.x <= 0→0.0. - Ceiling
Fibonacci - Smallest Fibonacci number
>= x.x <= 0→0.0. - Closest
Base10 - Power of ten nearest to
xby absolute distance (ties → floor).x <= 0→0.0. - Closest
Binomial - Power of two nearest to
xby absolute distance (ties → floor).x <= 0→0.0. - Closest
Decade - Round
xto the nearest multiple of its base-ten magnitude:round(x/base)*base.x <= 0→0.0. - Closest
Fibonacci - Fibonacci number nearest to
xby absolute distance (ties → floor).x <= 0→0.0. - Floor
Base10 - Largest power of ten
<= x:10^floor(log10(x)).x <= 0→0.0. - Floor
Binomial - Largest power of two
<= x:2^floor(log2(x)).x <= 0→0.0. - Floor
Decade - Round
xdown to a multiple of its base-ten magnitude:floor(x/base)*base.x <= 0→0.0. - Floor
Fibonacci - Largest Fibonacci number
<= x.x < 1(incl.x <= 0) →0.0. - Round
Ceiling - Round
xup to a multiple ofinterval:ceil(x/interval)*interval.interval <= 0or non-finite → returnsxunchanged (identity). - Round
Floor - Round
xdown to a multiple ofinterval:floor(x/interval)*interval.interval <= 0or non-finite → returnsxunchanged (identity). - Round
Nearest - Round
xto the nearest multiple ofinterval:round(x/interval)*interval.interval <= 0or non-finite → returnsxunchanged (identity).
Functions§
- ceiling_
fibonacci_ val - Smallest Fibonacci number (
1, 2, 3, 5, 8, …) that is>= x;1.0forx <= 1. Assumespositive_finite(x). - floor_
fibonacci_ val - Largest Fibonacci number (
1, 2, 3, 5, 8, …) that is<= x, or0.0whenx < 1(nothing in the sequence is that small). Assumes finitex. - floor_
pow2 - Largest power of two
2^n <= x. Assumespositive_finite(x). - floor_
pow10 - Largest power of ten
10^n <= x. Assumespositive_finite(x). - pick_
closest - Pick whichever of
lo/hiis nearer toxby absolute distance. Ties resolve tolo(the floor), per theclosest_*contract. - positive_
finite - True only for a strictly-positive, finite
x. All family selectors gate on this and return0.0otherwise, sox <= 0,NaN, and±infall fold to the zero magnitude without special-casing each node.