nexus-decimal
Fixed-point decimal arithmetic with compile-time precision.
Decimal<B, DECIMALS> is a generic fixed-point type parameterized by backing
integer and decimal places. Operations are const fn where possible,
zero-allocation, and designed for financial workloads.
Quick Start
use Decimal;
use FromStr;
type D64 = ;
let price = D64from_str.unwrap;
let qty = D64from_i32.unwrap;
let notional = price * qty;
assert_eq!;
Choosing Your Type
Define type aliases that match your domain:
use Decimal;
type Price = ; // 8dp, range ±92B — traditional finance
type Quantity = ; // 4dp, range ±922T
type CryptoPrice = ; // 12dp, range ±39T — DeFi
type Usd = ; // 2dp cents
| Backing | Max Decimals | Use case |
|---|---|---|
i32 |
9 | Embedded, space-constrained |
i64 |
18 | Traditional finance |
i128 |
38 | Cryptocurrency, DeFi |
Features
- Compile-time constants —
const fnconstructors and checked arithmetic - Zero allocation — all operations are stack-based
- Checked, saturating, and wrapping arithmetic variants
- Parsing —
FromStrwith strict validation - Display — configurable precision, scientific notation
- Serialization — optional
serdesupport
Feature Flags
| Flag | Default | Description |
|---|---|---|
std |
yes | Standard library support |
serde |
no | Serialize/deserialize support |
num-traits |
no | num-traits trait implementations |
License
See LICENSE.