#arithmetic #fixed-point #decimal #up #digits #decimal-digits #display

dfkzr

Dezimalfestkommazahlrechnung - decimal fixed point arithmetic with up to 19 digits

1 unstable release

0.1.0 Jun 13, 2023

#1613 in Math

LGPL-3.0-or-later

130KB
2.5K SLoC

Dezimalfestkommazahlrechnung

Features

  • Basic unsigned fixed-point arithmetic
  • Wrapper types implementing arithmetic traits for convenience, see UDf64Checked and UDf64Saturating
  • up to 19 effective decimal digits (integer part and fractional combined)
  • #![no_std] compatible, no runtime dependencies except core (except for some tests)
  • No heap allocations
  • Written in straightforward safe Rust, accompanied by an extensive automated test suite
  • Display

Planned features:

  • signed type
  • TryFrom<&str>, FromStr
  • narrowing/widening casts

Possible future features:

  • approximations for:
    • square root, higher order roots
    • exp, log
    • trig functions
  • conversion to/from float
  • NonZero variants
  • u32-based variants
  • localized Display/parse

Non- and anti-goals:

  • Choosing precision/width at runtime
  • Unchecked/wrapping or panicking API (just use .unwrap())
  • Performance: All basic operations are implemented with a handful of operations on u64 or u128 (and overflow checks), so performance should be decent. I don't care enough to make benchmarks though.

Dependencies

~0–670KB
~14K SLoC