Skip to main content

Context

Struct Context 

Source
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>

Source

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.

Source

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>

Source

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

pub fn div<const B: Word>( &self, z: &CBig<R, B>, w: &CBig<R, B>, ) -> CfpResult<R, B>

Divide two complex numbers under this context (context layer), using Smith’s overflow-safe method: the branch |u| >= |v| avoids forming |denominator|².

Source

pub fn div_real<const B: Word>( &self, z: &CBig<R, B>, s: &FBig<R, B>, ) -> CfpResult<R, B>

Divide a complex number by a real scalar (context layer): (x+iy)/s = (x/s) + i(y/s).

Source§

impl<R: Round> Context<R>

Source

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).

Source

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.

Source

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>

Source

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>

Source

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).

Source

pub fn sin<const B: Word>( &self, z: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> CfpResult<R, B>

Complex sine (context layer).

Source

pub fn cos<const B: Word>( &self, z: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> CfpResult<R, B>

Complex cosine (context layer).

Source

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).

Source

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

pub fn acos<const B: Word>( &self, z: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> CfpResult<R, B>

Inverse cosine acos z = -i·log(z + i·sqrt(1-z²)) (context layer, Kahan form).

Source

pub fn atan<const B: Word>( &self, z: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> CfpResult<R, B>

Inverse tangent atan z = (i/2)·(log(1-iz) - log(1+iz)) (context layer).

Source§

impl<R: Round> Context<R>

Source

pub fn neg<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>

Negate under this context (context layer). Exact.

Source

pub fn conj<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>

Complex conjugate under this context (context layer). Exact.

Source

pub fn proj<const B: Word>(&self, z: &CBig<R, B>) -> CfpResult<R, B>

Riemann projection under this context (context layer). Exact.

Source

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.

Source

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

pub fn arg<const B: Word>( &self, z: &CBig<R, B>, cache: Option<&mut ConstCache>, ) -> FpResult<FBig<R, B>>

The argument atan2(im, re) (context layer). Delegates to dashu-float’s Annex-G atan2; the cache threads into it (the convenience layer passes None).

Source

pub fn abs<const B: Word>(&self, z: &CBig<R, B>) -> FpResult<FBig<R, B>>

The modulus |z| = hypot(re, im) (context layer). Near-correctly rounded; returns +∞ for an infinite input. Thin composition over dashu_float::Context::hypot.

§Panics

Panics if the precision is unlimited.

Source§

impl<R: Round> Context<R>

Source

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

pub fn mul<const B: Word>( &self, z: &CBig<R, B>, w: &CBig<R, B>, ) -> CfpResult<R, B>

Multiply two complex numbers under this context: (x+iy)(u+iv) = (xu-yv) + i(xv+yu) (naive 4-mul form; near-correctly rounded via the guard re-round).

Source

pub fn mul_real<const B: Word>( &self, z: &CBig<R, B>, s: &FBig<R, B>, ) -> CfpResult<R, B>

Multiply a complex number by a real scalar (context layer): (x+iy)·s = (xs) + i(ys).

Source§

impl<R: Round> Context<R>

Source

pub const fn new(precision: usize) -> Self

Create a CBig operation context with the given precision limit (0 = unlimited).

Source

pub const fn max(lhs: Self, rhs: Self) -> Self

Create a context with the higher precision from the two inputs (unlimited 0 dominates).

Source

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.

Source

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>

Source

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.

Trait Implementations§

Source§

impl<R: Clone + Round> Clone for Context<R>

Source§

fn clone(&self) -> Context<R>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R: Copy + Round> Copy for Context<R>

Auto Trait Implementations§

§

impl<R> Freeze for Context<R>

§

impl<R> RefUnwindSafe for Context<R>
where R: RefUnwindSafe,

§

impl<R> Send for Context<R>
where R: Send,

§

impl<R> Sync for Context<R>
where R: Sync,

§

impl<R> Unpin for Context<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for Context<R>

§

impl<R> UnwindSafe for Context<R>
where R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.