zenith-float
Arbitrary-precision software floating-point numbers in Rust, plus software IEEE-754 binary32/binary64 (Ieee32 / Ieee64) and 1-D arrays. Current release: 1.0.2. First stable release: 1.0.0 on crates.io.
All arithmetic runs on integer limbs. The library does not use hardware floating-point registers for calculations. Construct ExactNum from integers or from binary, octal, decimal, or hexadecimal strings; construct IEEE widths from integer bit patterns (from_bits).
The library can work without std if a memory allocator is available.
Besides the usual + − × ÷ and the elementary functions (sqrt, exp, exp2, exp10, ln, trig, hyperbolic), the public API includes hypot, atan2, log1p, expm1, rem_pi, specials (erf, gamma, bessel_j, Jacobi sn/cn/dn), IEEE split (frexp, ldexp, logb), extra constants (√2, φ, γ), cexpr! for complex expressions, and SharedConsts for sharing a constant cache across threads.
License: MIT OR Apache-2.0. See CONTRIBUTING.md if you want to report a bug or send a patch.
Crate layout
zenith-float— public crate:ExactNum,Ieee32/Ieee64, arrays,expr!,cexpr!, constants, rounding.zenith-float-num— numeric kernel (you normally depend onzenith-floatonly).zenith-float-macro—expr!/cexpr!procedural macros.
Documentation
- Capabilities — what the crate does and does not do
- Getting started
- Help — recipes, mistakes, FAQ
- Library — public API
expr!rounding- Precision
- Reproducibility
- Contributing
- rustdoc: https://docs.rs/zenith-float
Features
| Feature | Default | Purpose |
|---|---|---|
std |
yes | Formatting, FromStr, serde (when enabled) |
random |
no | ExactNum::random_normal for tests and fuzzing |
serde |
no | Serialize/deserialize as a decimal string or integer (std required) |
mpfr-tests |
no | Optional MPFR comparison tests (Linux x86_64, needs rug) |
std is on by default (formatting and FromStr):
[]
= "1.0"
no_std (allocator required):
[]
= { = "1.0", = false }
Rounding
ExactNummethods that take a rounding mode other thanRoundingMode::Noneround the result to the requested precision.RoundingMode::Noneskips that final rounding and may keep extra bits.expr!raises working precision to compensate cancellation. It does not itself perform correct rounding; the completion of a rounding loop in finite time depends on the expression.- Overflow of the configured exponent range becomes
±Inf. Allocation and invalid arguments becomeNaN;ExactNum::err()returns the associatedError. - Subnormals,
NaN, and infinities are software values, not hardware floating-point registers.
Example
use Consts;
use RoundingMode;
use Context;
use expr;
let mut ctx = new;
let pi = expr!;
let pi_lib = ctx.const_pi;
assert_eq!;
Set the smallest exponent range that still holds your results. Internal working precision can grow with the exponent.
Tests
From this directory:
Debug tests must finish in 10 minutes and the MPFR gate in 30 minutes (CI_DEBUG_SECS / CI_MPFR_SECS). Replay a random failure with ZENITH_TEST_SEED=<seed> cargo test <name> -- --test-threads=1 (the seed is printed on panic).
That runs the default workspace tests, std-only tests, and tests with random and serde enabled. On Linux x86_64 the script also runs MPFR goldens in release:
Benchmarks (Criterion, release profile, deterministic fixtures):
Regression baselines live in doc/bench-baselines.tsv (tab-separated). REGRESSION_PCT defaults to 15.
Cross-library comparison (bigfloat-bench compatible workloads, TSV output):