Skip to main content

Crate use_number

Crate use_number 

Source
Expand description

§use-number

Small numeric constants and floating-point classification helpers for `RustUse`.
Explicit raw-number helpers that complement `use-real` without pulling in a broader numeric framework.

Rust 1.95.0+ Edition 2024 Number helpers License MIT or Apache-2.0

Surface · When to use it · Installation · Examples · Scope

use-number provides a deliberately small raw-number surface. The first concrete slice focuses on two things that are useful across the workspace without overlapping the validated wrappers in use-real: reusable numeric constants and explicit classification of plain f64 values.

Floating-point classification
NumberCategory, NumberSign, classify_number, and classify_number_sign make branching on raw f64 shape explicit.
Finite checks
is_finite_number keeps lightweight guard clauses available when introducing a full wrapper type would be too heavy.
Reusable constants
GOLDEN_RATIO and SQRT_3 provide small workspace-owned constants alongside their f32 variants.

§What this crate provides

AreaRoot exportsBest fit
Number classificationNumberCategory, NumberSign, classify_number, classify_number_signRaw f64 branching without ad hoc match logic on FpCategory
Lightweight finite checksis_finite_numberGuard clauses before opting into a heavier validated wrapper
ConstantsGOLDEN_RATIO, GOLDEN_RATIO_F32, SQRT_3, SQRT_3_F32Small numeric formulas and geometric ratios
If you need to…Start here
Branch on whether a raw f64 is normal, zero, subnormal, infinite, or NaNclassify_number(...)
Separate negative, zero, and positive raw values while keeping NaN explicitclassify_number_sign(...)
Add a fast finiteness guard without introducing a wrapper typeis_finite_number(...)
Reuse the golden ratio or sqrt(3) in small formulasGOLDEN_RATIO or SQRT_3

§When to use it directly

Choose use-number directly when raw-number helpers are the only surface you need and you want to stay narrower than use-math or use-real.

ScenarioUse use-number directly?Why
You need raw floating-point classification helpersYesThe crate stays small and explicit
You need a couple of reusable numeric constants in one placeYesThe constants are available without broader wrappers
You want validated finite values or checked intervalsUsually nouse-real keeps those invariants attached to types
You need domain-specific integer, rational, probability, or geometry APIsNoThose belong in adjacent focused crates

§Installation

[dependencies]
use-number = "0.0.1"

§Quick examples

§Classify raw floating-point values

use use_number::{NumberCategory, NumberSign, classify_number, classify_number_sign, is_finite_number};

assert_eq!(classify_number(f64::NAN), NumberCategory::Nan);
assert_eq!(classify_number(f64::from_bits(1)), NumberCategory::Subnormal);
assert_eq!(classify_number(0.0), NumberCategory::Zero);
assert_eq!(classify_number_sign(-12.5), Some(NumberSign::Negative));
assert_eq!(classify_number_sign(f64::NAN), None);
assert!(is_finite_number(3.5));
assert!(!is_finite_number(f64::INFINITY));

§Reuse common numeric constants

use use_number::{GOLDEN_RATIO, SQRT_3};

assert!(((GOLDEN_RATIO * GOLDEN_RATIO) - (GOLDEN_RATIO + 1.0)).abs() < 1.0e-12);
assert!(((SQRT_3 * SQRT_3) - 3.0).abs() < 1.0e-12);

§Scope

  • The initial surface stays concrete and small.
  • use-number focuses on raw-number helpers that do not need a validated wrapper type.
  • Validated finite values and intervals still belong in use-real.
  • Broader numeric traits and heavier abstractions remain out of scope for this first slice.

§Status

use-number is a concrete pre-1.0 crate in the RustUse docs surface. The API remains intentionally small while adjacent numeric crates continue to grow around it. Numeric building blocks for RustUse.

Re-exports§

pub use constants::GOLDEN_RATIO;
pub use constants::GOLDEN_RATIO_F32;
pub use constants::SQRT_3;
pub use constants::SQRT_3_F32;
pub use number::NumberCategory;
pub use number::NumberSign;
pub use number::classify_number;
pub use number::classify_number_sign;
pub use number::is_finite_number;

Modules§

constants
Small numeric constants that are reused across the workspace.
number
Raw-number classification helpers.
prelude
Common ergonomic imports for use-number.