Docs • Performance • Comparisons • Algorithms • Roadmap • API reference
A fast, precise, decimal library.
- Decimal storage — unlike floating point,
1.1is exactly1.1. - Multiple rounding modes — six in total,
HalfToEvenby default. - Up to 4 Kb numbers — twelve widths,
D18toD1232. - Choose your precision at compile time — from 0 to one less than the width. i.e. D1232 can carry a precision of 1231 digits.
no_stdfriendly — the strict, integer-only path needs nostd.- Validated by 71,469,918 value tests — every width × scale × rounding mode.
[dependencies]
decimal-scaled = { version = "0.5", features = ["macros"] }use decimal_scaled::{d38, D38s12};
// The most common way to make a value: a literal, scale inferred from
// its digits.
let x = d38!(1.564232); // D38<6>
assert_eq!(x.to_string(), "1.564232");
let price: D38s12 = "19.99".parse().unwrap();
let qty = D38s12::try_from(3i64).unwrap(); // integer, scaled by 10^SCALE (fallible)
let total = price * qty; // 59.97 exactly
assert_eq!(total.to_string(), "59.97");
assert_eq!(total, d38!(59.97, scale 12));
// Transcendentals are correctly rounded to <= 0.5 ULP, integer-only,
// and bit-identical across platforms.
let sqrt2 = d38!(2, scale 12).sqrt_strict();| You need… | decimal-scaled gives you… |
|---|---|
Decimal arithmetic that doesn't drift (0.1 + 0.2 == 0.3) |
Base-10 storage; exact + - %, correctly-rounded * /. |
| Bit-identical results across Linux / macOS / Windows / ARM / x86 | *_strict transcendentals — integer-only, no platform libm. |
| Compile-time-fixed precision with zero per-value scale byte | Const-generic D38<19>, D76<35> etc. — scale is in the type. |
no_std (or no_std + alloc) |
Builds under no_std + alloc with default-features = false; the strict, integer-only path needs no libm. |
Correctly-rounded ln / exp / sin / cos / tan / sqrt / atan and friends — by default |
Within 0.5 ULP, HalfToEven by default; switch per call via *_with(mode) or crate-wide via the rounding-* features. |
Full docs: https://mootable.github.io/decimal-scaled/.
- Getting started — constructing values, arithmetic, formatting, parsing.
- The width family —
D18throughD1232, scale aliases, theDecimaltrait, picking a tier. - Conversions — integers, floats, cross-width widening / narrowing, the float bridge.
- Cross-scale operations — mixed-width, mixed-
SCALEexpressions viamul_of/add_of/cmp_of/clamp_of, plus the nightly auto-inferred form. - Rounding —
RoundingMode, the_withpairs,rescale, the compile-timerounding-*features. - Strict vs fast transcendentals — the integer-only
*_strictpath and the 0.5 ULP guarantee. - The
d*!macros — compile-time decimal literals and scale inference. - Cargo features — every feature flag and the common configurations.
- Bench — per-width Performance, the Precision surface, version History, the golden Harness, and the like-for-like Comparisons against the top crates.io peers.
- Algorithms — every kernel with its citation (Möller–Granlund, Brent, Knuth, Karatsuba, Burnikel–Ziegler, Cody–Waite, …).
- Roadmap · Changelog · Contributing.
API reference: https://docs.rs/decimal-scaled/.
Licensed under either of:
- MIT license (LICENSES/MIT.md)
- Apache License, Version 2.0 (LICENSES/Apache-2.0.md)
at your option.
Copyright 2026 John Moxley. Third-party code attributions are listed in LICENSE-THIRD-PARTY.