Expand description
A big arbitrary precision complex number library.
The library provides the type CBig: an arbitrary-precision complex number built on top of
dashu_float’s FBig. Each CBig stores a real and an imaginary part (Repr) over a
single shared precision and rounding mode, mirroring FBig’s Repr+Context layout. It
targets parity with GNU MPC for the common functionalities (field arithmetic + elementary
transcendentals + abs/arg/conj/proj + I/O).
Rounding follows the C99 Annex G / Kahan branch-cut and signed-zero model that dashu-float
already implements for reals. There is no NaN: C99 NaN-producing cases are mapped to
FpError at the Context layer (and panics at the convenience layer), exactly mirroring
how FBig behaves.
§Two-layer API
Like FBig, operations come in two layers:
- Context layer —
Contextmethods return aCfpResult(Result<CRounded<CBig>, FpError>) carrying per-axis inexactness(Rounding, Rounding). - Convenience layer —
CBigmethods and operators unwrap to a plainCBig, panicking onIndeterminate/OutOfDomain/InfiniteInputand saturatingOverflow/Underflow.
§Examples
use dashu_cmplx::CBig;
use dashu_float::{FBig, round::mode::HalfAway};
type C = CBig<HalfAway, 10>; // base-10 so values render as decimals
let z = C::from_parts(FBig::from(3), FBig::from(4));
let w = C::I;
let sum = &z + &w; // (3+4i) + i = 3+5i
assert_eq!(sum.re().significand(), &3.into());
assert_eq!(sum.im().significand(), &5.into());
// algebraic display
assert_eq!(format!("{}", sum), "3+5i");§Optional dependencies
std(default): enablestdfor dependencies.num-order(default):NumOrd/NumHashforCBig.num-complex:TryFromconversions betweenCBigandnum-complex’sComplex<f32>/Complex<f64>(base-2, mirroringFBig’s primitive-float conversions).
Modules§
- math
- Advanced mathematical functions.
- rand
- Random complex number generation with the
randcrate. - round
- Traits and implementations for rounding during operations.
Structs§
- CBig
- An arbitrary-precision complex number with arbitrary base and rounding mode.
- CachedC
Big - A complex number that carries a shared handle to a
ConstCache. - Const
Cache - An opt-in cache of mathematical constants.
- Context
- CBig operation context — a newtype wrapper around
dashu_float::Context, and also the type stored on eachCBigas its shared precision/rounding config (soCBig::contextreturns it directly, with no wrapping). - FBig
- An arbitrary precision floating point number with arbitrary base and rounding mode.
- Repr
- Underlying representation of an arbitrary precision floating number.
Enums§
- FpError
- Error returned by floating-point operations that cannot produce a usable result.
- Rounding
- The adjustment of a rounding operation
Traits§
- Round
- A trait describing the rounding strategy
Type Aliases§
- CRounded
- Correctly-rounded complex result with per-axis inexactness.
- CfpResult
- The result of a context-layer CBig operation: a correctly-rounded
CBig(with per-axis inexactness) or anFpError. The complex analog ofdashu_float::FpResult.