| Crates.io | precision-core |
| lib.rs | precision-core |
| version | 0.1.0-alpha.2 |
| created_at | 2026-01-24 12:13:53.934264+00 |
| updated_at | 2026-01-25 18:00:32.651976+00 |
| description | Deterministic fixed-point arithmetic for financial computation |
| homepage | |
| repository | https://github.com/dijkstra-keystone/keystone |
| max_upload_size | |
| id | 2066585 |
| size | 107,089 |
Deterministic fixed-point arithmetic for financial computation.
no_std compatible for embedded and WASM targets[dependencies]
precision-core = "0.1"
use precision_core::{Decimal, RoundingMode};
// From integers
let a = Decimal::from(100i64);
// From mantissa and scale: value = mantissa * 10^(-scale)
let b = Decimal::new(12345, 2); // 123.45
// Checked arithmetic
let sum = a.checked_add(b).unwrap();
let product = a.checked_mul(b).unwrap();
// Rounding
let rounded = b.round(1, RoundingMode::HalfUp); // 123.5
// Transcendental functions
let sqrt = Decimal::from(2i64).try_sqrt().unwrap(); // ~1.414...
let exp = Decimal::ONE.try_exp().unwrap(); // ~2.718...
let ln = Decimal::from(10i64).try_ln().unwrap(); // ~2.302...
use precision_core::oracle::{normalize_oracle_price, OracleDecimals};
// Chainlink BTC/USD (8 decimals)
let btc_raw = 5000012345678i64; // $50,000.12345678
let btc_price = normalize_oracle_price(btc_raw, OracleDecimals::Eight)?;
// Convert between decimal formats
use precision_core::oracle::convert_decimals;
let usdc_amount = convert_decimals(1000000, OracleDecimals::Six, OracleDecimals::Eighteen)?;
| Mode | Description |
|---|---|
HalfEven |
Banker's rounding (default) |
HalfUp |
Traditional rounding |
HalfDown |
Ties toward zero |
Up |
Toward +infinity |
Down |
Toward -infinity |
TowardZero |
Truncation |
AwayFromZero |
Away from zero |
The crate is no_std by default. Enable the std feature for standard library support:
[dependencies]
precision-core = { version = "0.1", features = ["std"] }
Licensed under either of Apache License, Version 2.0 or MIT license at your option.