| Crates.io | brine-fp |
| lib.rs | brine-fp |
| version | 0.2.1 |
| created_at | 2025-04-10 19:42:27.487734+00 |
| updated_at | 2025-07-28 16:24:49.181169+00 |
| description | 192-bit fixed-point math library with logarithmic and exponential functions. Designed for blockchain, scientific, and financial applications. |
| homepage | |
| repository | https://github.com/zfedoran/brine-fp |
| max_upload_size | |
| id | 1628776 |
| size | 85,581 |
brine-fp is a 192-bit fixed-point math library built for high-precision, deterministic computation in constrained environments like the Solana SVM. It provides arithmetic, exponentiation, logarithms, and powers using u192-based representations, and is optimized for low compute unit (CU) usage on-chain.
| Operation | CU (Approx.) |
|---|---|
log(2) |
~18,500 |
exp(0.5) |
~15,000 |
pow(2, ½) |
~100 |
frexp(2) |
~150 |
These values are measured inside the Solana SVM (via test programs).
log, exp, pow, floor, ceil, almost_eq, etc.msun.use brine_fp::UnsignedNumeric;
// Construct a fixed-point number: 5.0
let five = UnsignedNumeric::new(5);
// Compute its exponential
let result = five.signed().exp().unwrap();
println!("e^5 ≈ {}", result.to_string());
Each UnsignedNumeric wraps a InnerUint([lo, mid, hi]), representing a 192-bit unsigned integer:
InnerUint([lo, mid, hi])
// Equivalent to:
// value = lo + (mid << 64) + (hi << 128)
All values are scaled by 10^18, enabling 18-digit decimal precision.
This format ensures:
1e-18 up to ~6.3 × 10³⁹ real-world unitsf64, no float)exp() or log() without f64brine-fp is heavily based on prior work and stands on the shoulders of giants. The core math and algorithms are derived from:
Contributions are welcome! Please open issues or PRs on the GitHub repo.