decimal-scaled - usage guides¶
Docs • Benchmarks • Algorithms • Roadmap • API reference
decimal-scaled provides const-generic, base-10 fixed-point decimal
types with deterministic, bit-exact arithmetic. A value is stored as an
integer raw such that the logical value is raw × 10^(-SCALE), where
SCALE is a compile-time const generic.
These guides cover how to use the library in depth. For the high-level pitch and the "why another numeric type" comparison, see the crate README. For the full API, see the rustdoc.
Guides¶
| Guide | What it covers |
|---|---|
| Getting started | Installing, constructing values, basic arithmetic, formatting, parsing. |
| The width family | D9 / D18 / D38 / D76 / D153 / D307 - when to pick which, scale ranges, the Decimal trait. |
| Conversions | Integer / float conversions, cross-width widening and narrowing, to_int, the float bridge. |
| Rounding | RoundingMode, the _with method pairs, rescale, and the compile-time rounding-* feature flags. |
| Strict mode | Integer-only transcendentals (ln, exp, sqrt, trig, …) under --features strict. |
The d38! macro |
Compile-time decimal literals with automatic scale inference, scientific notation, explicit scale, rounding, and inline expressions. |
| Cargo features | Every feature flag and what it enables. |
| Benchmarks | Head-to-head timings against bnum, ruint, rust_decimal, and fixed; fast vs strict transcendentals; the 0.5 ULP guarantee. |
A 30-second tour¶
use decimal_scaled::{D38s2, d38};
// Compile-time literal - scale inferred from the written digits.
let price = d38!(19.99); // D38s2, exactly 19.99
let qty = D38s2::from_int(3); // 3.00
let total = price * qty; // 59.97, exact - no binary rounding
assert_eq!(total, d38!(59.97));
// Deterministic: identical bit pattern on every platform.
assert_eq!(total.to_bits(), 5997);