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.
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 classificationNumberCategory, NumberSign, classify_number, and classify_number_sign make branching on raw f64 shape explicit.
|
Finite checksis_finite_number keeps lightweight guard clauses available when introducing a full wrapper type would be too heavy.
|
Reusable constantsGOLDEN_RATIO and SQRT_3 provide small workspace-owned constants alongside their f32 variants.
|
§What this crate provides
| Area | Root exports | Best fit |
|---|---|---|
| Number classification | NumberCategory, NumberSign, classify_number, classify_number_sign | Raw f64 branching without ad hoc match logic on FpCategory |
| Lightweight finite checks | is_finite_number | Guard clauses before opting into a heavier validated wrapper |
| Constants | GOLDEN_RATIO, GOLDEN_RATIO_F32, SQRT_3, SQRT_3_F32 | Small numeric formulas and geometric ratios |
| If you need to… | Start here |
|---|---|
Branch on whether a raw f64 is normal, zero, subnormal, infinite, or NaN | classify_number(...) |
| Separate negative, zero, and positive raw values while keeping NaN explicit | classify_number_sign(...) |
| Add a fast finiteness guard without introducing a wrapper type | is_finite_number(...) |
Reuse the golden ratio or sqrt(3) in small formulas | GOLDEN_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.
| Scenario | Use use-number directly? | Why |
|---|---|---|
| You need raw floating-point classification helpers | Yes | The crate stays small and explicit |
| You need a couple of reusable numeric constants in one place | Yes | The constants are available without broader wrappers |
| You want validated finite values or checked intervals | Usually no | use-real keeps those invariants attached to types |
| You need domain-specific integer, rational, probability, or geometry APIs | No | Those 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-numberfocuses 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;