Skip to main content

Crate dashu_cmplx

Crate dashu_cmplx 

Source
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 layerContext methods return a CfpResult (Result<CRounded<CBig>, FpError>) carrying per-axis inexactness (Rounding, Rounding).
  • Convenience layerCBig methods and operators unwrap to a plain CBig, panicking on Indeterminate / OutOfDomain / InfiniteInput and saturating Overflow/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): enable std for dependencies.
  • num-order (default): NumOrd/NumHash for CBig.
  • num-complex: TryFrom conversions between CBig and num-complex’s Complex<f32>/ Complex<f64> (base-2, mirroring FBig’s primitive-float conversions).

Modules§

math
Advanced mathematical functions.
rand
Random complex number generation with the rand crate.
round
Traits and implementations for rounding during operations.

Structs§

CBig
An arbitrary-precision complex number with arbitrary base and rounding mode.
CachedCBig
A complex number that carries a shared handle to a ConstCache.
ConstCache
An opt-in cache of mathematical constants.
Context
CBig operation context — a newtype wrapper around dashu_float::Context, and also the type stored on each CBig as its shared precision/rounding config (so CBig::context returns 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 an FpError. The complex analog of dashu_float::FpResult.