#wad #decimal #float #serialization #precision #math

decimal-wad

Math for preserving precision floats up to 18 decimal places

8 releases

0.1.8 Oct 27, 2022
0.1.7 Aug 22, 2022
0.1.6 Jul 20, 2022
0.1.5 Mar 21, 2022
0.1.2 Nov 30, 2021

#290 in Math

Download history 534/week @ 2022-12-01 183/week @ 2022-12-08 267/week @ 2022-12-15 132/week @ 2022-12-22 107/week @ 2022-12-29 441/week @ 2023-01-05 93/week @ 2023-01-12 217/week @ 2023-01-19 166/week @ 2023-01-26 170/week @ 2023-02-02 214/week @ 2023-02-09 208/week @ 2023-02-16 123/week @ 2023-02-23 63/week @ 2023-03-02 55/week @ 2023-03-09 79/week @ 2023-03-16

352 downloads per month

MIT license

19KB
491 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