#decimal #math #precision #arithmetic-operations #place #floats #preserving

decimal-wad

Math for preserving precision floats up to 18 decimal places

9 releases

0.1.9 May 31, 2023
0.1.8 Oct 27, 2022
0.1.7 Aug 22, 2022
0.1.6 Jul 20, 2022
0.1.2 Nov 30, 2021

#544 in Algorithms

Download history 71/week @ 2024-03-10 76/week @ 2024-03-17 61/week @ 2024-03-24 81/week @ 2024-03-31 42/week @ 2024-04-07 174/week @ 2024-04-14 123/week @ 2024-04-21 84/week @ 2024-04-28 101/week @ 2024-05-05 98/week @ 2024-05-12 101/week @ 2024-05-19 473/week @ 2024-05-26 66/week @ 2024-06-02 132/week @ 2024-06-09 86/week @ 2024-06-16 239/week @ 2024-06-23

535 downloads per month

MIT license

23KB
673 lines

Decimal WAD

Math for preserving precision floats which are limited to be at most u64::MAX.

  • Decimals are internally scaled by a WAD (10^18) to preserve precision up to 18 decimal places.
  • Decimals are sized to support both serialization and precise math for the full range of unsigned 64-bit integers.
  • The underlying representation of decimals is a u192 rather than u256 to reduce compute cost while losing support for arithmetic operations at the high end of u64 range.
  • Rates are sized to support both serialization and precise math for the full range of unsigned 8-bit integers.
  • The underlying representation of rates is a u128 rather than u192 to reduce compute cost while losing support for arithmetic operations at the high end of u8 range.

Dependencies

~245KB