1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! # fermat-core
//!
//! 128-bit fixed-point decimal arithmetic for Solana's sBPF runtime.
//!
//! ## Design Goals
//!
//! - **`no_std`**: Works on Solana sBPF without any OS dependencies.
//! - **Zero external dependencies**: Only `proptest` appears as a dev-dependency.
//! - **Panic-free**: Every fallible operation returns `Result<_, ArithmeticError>`.
//! - **`#![forbid(unsafe_code)]`**: No unsafe blocks anywhere in the crate.
//! - **Overflow-safe `mul_div`**: Uses a 256-bit intermediate (`U256`) to prevent
//! the class of bugs where `(a × b) / c` silently wraps when `a × b` overflows `i128`.
//!
//! ## Core Type
//!
//! ```text
//! Decimal { mantissa: i128, scale: u8 }
//! value = mantissa × 10^(-scale)
//! ```
//!
//! The `scale` is bounded to `[0, 28]` (`MAX_SCALE`). On-chain Borsh encoding is
//! exactly 17 bytes (16 bytes mantissa LE + 1 byte scale).
//!
//! ## Quick Start
//!
//! ```rust
//! use fermat_core::{Decimal, RoundingMode};
//!
//! let price = Decimal::new(150_000_000, 6).unwrap(); // 150.000000
//! let amount = Decimal::new(2_500_000, 6).unwrap(); // 2.500000
//! let total = price.checked_mul(amount).unwrap(); // 375.000000...
//! let result = total.round(6, RoundingMode::HalfEven).unwrap();
//! ```
extern crate alloc;
pub use ;
pub use ArithmeticError;
pub use RoundingMode;