Skip to content
Bit-exact decimal arithmetic for Rust

decimal-scaled

A fast, precise, decimal library.

  • Decimal storage — unlike floating point, 1.1 is exactly 1.1.
  • Multiple rounding modes — six in total, HalfToEven by default.
  • Up to 4 Kb numbers — twelve widths, D18 to D1232.
  • 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_std friendly — the strict, integer-only path needs no std.
  • Validated by 71,469,918 value tests — every width × scale × rounding mode.
$ cargo add decimal-scaled

Get started Benchmarks GitHub


  • Getting started

    Install snippet, the first D38<2> value, and a tour of the per-width macros.

    getting-started.md

  • Reference

    Per-topic reference pages: widths, rounding, conversions, serde, cross-scale operations, glossary.

    reference.md

  • Bench

    Per-width speed tables, the precision surface, version history, and the like-for-like library comparison vs the top crates.io peers.

    performance.md

  • Correctness, proven

    How the golden harness asserts every answer bit-exact against a multi-oracle set, for every rounding mode, across every shipped width.

    golden.md

  • API reference

    Rustdoc for every type, trait, method, and Cargo feature across every supported width.

    api/decimal_scaled/index.html

  • Algorithms

    Möller–Granlund magic-multiply, artanh-series transcendentals, Cody-Waite range reduction - the catalogue of techniques the crate uses and why.

    ALGORITHMS.md

  • Project

    Where the crate is heading, what changed in every release, and how to contribute.

    ROADMAP.md · CHANGELOG.md


Why decimal-scaled

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.
≤ 0.5 ULP correctly-rounded ln / exp / sin / cos / tan / sqrt / atan / sinh / cosh / tanh and friends — by default At every shipped width, HalfToEven by default, bit-identical across every platform. Switch rounding mode per call via *_with(mode) or crate-wide via the rounding-* features. See Comparisons.