Skip to main content

Module round_numbers

Module round_numbers 

Source
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§

CeilingBase10
Smallest power of ten >= x: 10^ceil(log10(x)). x <= 00.0.
CeilingBinomial
Smallest power of two >= x: 2^ceil(log2(x)). x <= 00.0.
CeilingDecade
Round x up to a multiple of its base-ten magnitude: ceil(x/base)*base. x <= 00.0.
CeilingFibonacci
Smallest Fibonacci number >= x. x <= 00.0.
ClosestBase10
Power of ten nearest to x by absolute distance (ties → floor). x <= 00.0.
ClosestBinomial
Power of two nearest to x by absolute distance (ties → floor). x <= 00.0.
ClosestDecade
Round x to the nearest multiple of its base-ten magnitude: round(x/base)*base. x <= 00.0.
ClosestFibonacci
Fibonacci number nearest to x by absolute distance (ties → floor). x <= 00.0.
FloorBase10
Largest power of ten <= x: 10^floor(log10(x)). x <= 00.0.
FloorBinomial
Largest power of two <= x: 2^floor(log2(x)). x <= 00.0.
FloorDecade
Round x down to a multiple of its base-ten magnitude: floor(x/base)*base. x <= 00.0.
FloorFibonacci
Largest Fibonacci number <= x. x < 1 (incl. x <= 0) → 0.0.
RoundCeiling
Round x up to a multiple of interval: ceil(x/interval)*interval. interval <= 0 or non-finite → returns x unchanged (identity).
RoundFloor
Round x down to a multiple of interval: floor(x/interval)*interval. interval <= 0 or non-finite → returns x unchanged (identity).
RoundNearest
Round x to the nearest multiple of interval: round(x/interval)*interval. interval <= 0 or non-finite → returns x unchanged (identity).

Functions§

ceiling_fibonacci_val
Smallest Fibonacci number (1, 2, 3, 5, 8, …) that is >= x; 1.0 for x <= 1. Assumes positive_finite(x).
floor_fibonacci_val
Largest Fibonacci number (1, 2, 3, 5, 8, …) that is <= x, or 0.0 when x < 1 (nothing in the sequence is that small). Assumes finite x.
floor_pow2
Largest power of two 2^n <= x. Assumes positive_finite(x).
floor_pow10
Largest power of ten 10^n <= x. Assumes positive_finite(x).
pick_closest
Pick whichever of lo / hi is nearer to x by absolute distance. Ties resolve to lo (the floor), per the closest_* contract.
positive_finite
True only for a strictly-positive, finite x. All family selectors gate on this and return 0.0 otherwise, so x <= 0, NaN, and ±inf all fold to the zero magnitude without special-casing each node.