Skip to main content

ancdec/
lib.rs

1//! A `#![no_std]` fixed-point decimal library with four types for different precision/size needs.
2//!
3//! | Type | Integer/Frac | Scale | Size |
4//! |---|---|---|---|
5//! | [`AncDec8`] | `u8` | 0-2 | 4 bytes |
6//! | [`AncDec32`] | `u32` | 0-9 | 12 bytes |
7//! | [`AncDec`] | `u64` | 0-19 | 24 bytes |
8//! | [`AncDec128`] | `u128` | 0-38 | 40 bytes |
9//!
10//! All types store integer and fractional parts separately with an explicit scale,
11//! avoiding the precision loss inherent in floating-point representations.
12//!
13//! # Feature flags
14//!
15//! - **`dec8`** / **`dec32`** / **`dec64`** / **`dec128`** -- enable individual types (all on by default)
16//! - **`serde`** -- string-based `Serialize`/`Deserialize`
17//! - **`sqlx`** -- PostgreSQL `NUMERIC` support (implies `std` + `dec64`)
18
19#![no_std]
20
21#[cfg(feature = "std")]
22extern crate std;
23
24// Shared modules (always compiled)
25mod error;
26mod round_mode;
27mod util;
28
29pub use error::ParseError;
30pub use round_mode::RoundMode;
31
32// Wide arithmetic: needed by dec32 (isqrt_u128), dec64 and dec128
33#[cfg(any(feature = "dec32", feature = "dec64", feature = "dec128"))]
34pub(crate) mod wide;
35
36// ============ AncDec8 (u8) ============
37#[cfg(feature = "dec8")]
38mod ancdec8;
39#[cfg(feature = "dec8")]
40pub use ancdec8::AncDec8;
41
42// ============ AncDec32 (u32) ============
43#[cfg(feature = "dec32")]
44mod ancdec32;
45#[cfg(feature = "dec32")]
46pub use ancdec32::AncDec32;
47
48// ============ AncDec (u64) ============
49#[cfg(feature = "dec64")]
50mod ancdec;
51#[cfg(feature = "dec64")]
52pub use ancdec::AncDec;
53
54// ============ AncDec128 (u128) ============
55#[cfg(feature = "dec128")]
56mod ancdec128;
57#[cfg(feature = "dec128")]
58pub use ancdec128::AncDec128;
59
60// ============ Cross-type operations ============
61mod cross_ops;