pub struct Context<R: Round>(/* private fields */);Expand description
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).
It is a separate type because inherent methods cannot be added to FBig’s Context from this
crate; it exists to host the context-layer CBig operations (Context::mul, Context::exp, …).
The config API just delegates inward to the wrapped float context.
Implementations§
Source§impl<R: Round> Context<R>
impl<R: Round> Context<R>
Sourcepub fn add<const B: Word>(
&self,
z: &CBig<R, B>,
w: &CBig<R, B>,
) -> CfpResult<R, B>
pub fn add<const B: Word>( &self, z: &CBig<R, B>, w: &CBig<R, B>, ) -> CfpResult<R, B>
Add two complex numbers under this context (context layer).
Returns a CfpResult carrying each part’s inexactness. Addition is componentwise, so each
part is a single correctly-rounded real addition.
Sourcepub fn sub<const B: Word>(
&self,
z: &CBig<R, B>,
w: &CBig<R, B>,
) -> CfpResult<R, B>
pub fn sub<const B: Word>( &self, z: &CBig<R, B>, w: &CBig<R, B>, ) -> CfpResult<R, B>
Subtract two complex numbers under this context (context layer).
Returns a CfpResult carrying each part’s inexactness. Subtraction is componentwise, so each
part is a single correctly-rounded real subtraction.
Source§impl<R: Round> Context<R>
impl<R: Round> Context<R>
Sourcepub fn inv<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>
pub fn inv<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>
Reciprocal 1/z = conj(z)/|z|² under this context (context layer).
Source§impl<R: Round> Context<R>
impl<R: Round> Context<R>
Sourcepub fn exp<const B: Word>(
&self,
z: &CBig<R, B>,
cache: Option<&mut ConstCache>,
) -> CfpResult<R, B>
pub fn exp<const B: Word>( &self, z: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> CfpResult<R, B>
Complex exponential under this context (context layer). Reuses dashu-float’s exp and
sin_cos; the cache is threaded into both (the convenience layer passes None).
Special values: exp(0) = 1; exp(+inf + i·finite) = +∞ (Riemann point);
exp(-inf + i·finite) = 0; an infinite imaginary part makes the trig undefined
(Indeterminate).
Sourcepub fn powi<const B: Word>(&self, z: &CBig<R, B>, exp: IBig) -> CfpResult<R, B>
pub fn powi<const B: Word>(&self, z: &CBig<R, B>, exp: IBig) -> CfpResult<R, B>
Raise a complex number to an integer power under this context (context layer), via repeated
squaring (branch-cut-free, cheaper than exp(n·log z)). No cache.
powi(z, 0) = 1; a negative exponent computes powi(z, |n|) then inverts.
Sourcepub fn powf<const B: Word>(
&self,
base: &CBig<R, B>,
w: &CBig<R, B>,
cache: Option<&mut ConstCache>,
) -> CfpResult<R, B>
pub fn powf<const B: Word>( &self, base: &CBig<R, B>, w: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> CfpResult<R, B>
Raise base to a complex power under this context (context layer): exp(w·log base) on the
principal branch, evaluated at p + POWF_GUARD and re-rounded. powf(0, 0) = 1 (matching
FBig::powf).
Unlike exp, this drives whole-CBig operations (log/mul/exp), so it builds a
complex working Context at guard precision directly rather than the float
Context::guard (which yields a FloatCtxt for per-part math).
Source§impl<R: Round> Context<R>
impl<R: Round> Context<R>
Sourcepub fn log<const B: Word>(
&self,
z: &CBig<R, B>,
cache: Option<&mut ConstCache>,
) -> CfpResult<R, B>
pub fn log<const B: Word>( &self, z: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> CfpResult<R, B>
Complex natural logarithm under this context (context layer). log z = ln|z| + i·arg(z),
with the imaginary part in ]−π, π]. The cache threads into ln and atan2.
Special values: log(0) = -∞ + i·0; log(±∞) = +∞; the branch cut on ]−∞, 0] is handled
by the signed-zero atan2 (so log(-r ± i0) = ln r ± iπ).
Source§impl<R: Round> Context<R>
impl<R: Round> Context<R>
Sourcepub fn sin_cos<const B: Word>(
&self,
z: &CBig<R, B>,
cache: Option<&mut ConstCache>,
) -> (CfpResult<R, B>, CfpResult<R, B>)
pub fn sin_cos<const B: Word>( &self, z: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> (CfpResult<R, B>, CfpResult<R, B>)
Simultaneously compute sin z and cos z (context layer). Returns (sin, cos) each as a
CfpResult. An infinite input maps to FpError::Indeterminate (the C99 NaN cases).
Sourcepub fn sin<const B: Word>(
&self,
z: &CBig<R, B>,
cache: Option<&mut ConstCache>,
) -> CfpResult<R, B>
pub fn sin<const B: Word>( &self, z: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> CfpResult<R, B>
Complex sine (context layer).
Sourcepub fn cos<const B: Word>(
&self,
z: &CBig<R, B>,
cache: Option<&mut ConstCache>,
) -> CfpResult<R, B>
pub fn cos<const B: Word>( &self, z: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> CfpResult<R, B>
Complex cosine (context layer).
Sourcepub fn tan<const B: Word>(
&self,
z: &CBig<R, B>,
cache: Option<&mut ConstCache>,
) -> CfpResult<R, B>
pub fn tan<const B: Word>( &self, z: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> CfpResult<R, B>
Complex tangent sin z / cos z (context layer).
Sourcepub fn asin<const B: Word>(
&self,
z: &CBig<R, B>,
cache: Option<&mut ConstCache>,
) -> CfpResult<R, B>
pub fn asin<const B: Word>( &self, z: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> CfpResult<R, B>
Inverse sine asin z = -i·log(iz + sqrt(1-z²)) (context layer, Kahan form). The argument of
the inner log always has positive real part, so the branch cut comes entirely from the
sqrt; an infinite input maps to FpError::Indeterminate.
Source§impl<R: Round> Context<R>
impl<R: Round> Context<R>
Sourcepub fn neg<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>
pub fn neg<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>
Negate under this context (context layer). Exact.
Sourcepub fn conj<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>
pub fn conj<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>
Complex conjugate under this context (context layer). Exact.
Sourcepub fn proj<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>
pub fn proj<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>
Riemann projection under this context (context layer). Exact.
Sourcepub fn mul_i<const B: Word>(
&self,
z: &CBig<R, B>,
negative: bool,
) -> CfpResult<R, B>
pub fn mul_i<const B: Word>( &self, z: &CBig<R, B>, negative: bool, ) -> CfpResult<R, B>
Multiply by ±i under this context (context layer). Exact rotation.
Sourcepub fn norm<const B: Word>(&self, z: &CBig<R, B>) -> FpResult<FBig<R, B>>
pub fn norm<const B: Word>(&self, z: &CBig<R, B>) -> FpResult<FBig<R, B>>
The squared modulus re² + im² (context layer). Near-exact; returns +∞ for an infinite
input and propagates overflow to a signed infinity via the float unwrap_fp policy.
Source§impl<R: Round> Context<R>
impl<R: Round> Context<R>
Sourcepub fn sqr<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>
pub fn sqr<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>
Square a complex number under this context: (x+iy)² = (x²-y²) + i(2xy).
Source§impl<R: Round> Context<R>
impl<R: Round> Context<R>
Sourcepub const fn new(precision: usize) -> Self
pub const fn new(precision: usize) -> Self
Create a CBig operation context with the given precision limit (0 = unlimited).
Sourcepub const fn max(lhs: Self, rhs: Self) -> Self
pub const fn max(lhs: Self, rhs: Self) -> Self
Create a context with the higher precision from the two inputs (unlimited 0 dominates).
Sourcepub const fn precision(&self) -> usize
pub const fn precision(&self) -> usize
The precision limit stored in the context (0 = unlimited). Both parts of a CBig always
share this single precision.
Sourcepub fn unwrap_cfp<const B: Word>(&self, result: CfpResult<R, B>) -> CBig<R, B>
pub fn unwrap_cfp<const B: Word>(&self, result: CfpResult<R, B>) -> CBig<R, B>
Unwrap a CfpResult, returning the CBig value directly.
The complex analog of dashu_float::Context::unwrap_fp. It drops the per-axis
(Rounding, Rounding) flags, and applies the same error policy: FpError::Overflow
saturates to a signed infinity, FpError::Underflow to a signed zero, and the remaining
variants panic.
Source§impl<R: Round> Context<R>
impl<R: Round> Context<R>
Sourcepub fn sqrt<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>
pub fn sqrt<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>
Principal square root of a complex number (context layer).
The result has non-negative real part; when the real part is zero the imaginary part is
non-negative. The branch cut lies on ]−∞, 0]; sqrt(conj z) == conj(sqrt z) holds, which
signed zero makes continuous across the cut.