Skip to main content

CBig

Struct CBig 

Source
pub struct CBig { /* private fields */ }
Expand description

Arbitrary-precision complex number re + im·i, with each component a decimal DBig.

See the crate-level documentation for the rationale behind the absence of Hash, Eq, and Ord.

Implementations§

Source§

impl CBig

Source

pub fn to_f64_parts(&self) -> (f64, f64)

Project both components down to f64, returning (re, im).

§Precision

This conversion is lossy: each arbitrary-precision DBig component is rounded to the nearest f64. Values whose magnitude exceeds f64::MAX saturate to ±∞, and digits beyond the 53-bit mantissa are discarded. Use it only when an ordinary floating-point approximation is acceptable.

§Examples
use oxinum_complex::CBig;
let z = CBig::from_f64(3.5, -1.25).expect("finite parts");
assert_eq!(z.to_f64_parts(), (3.5, -1.25));
Source§

impl CBig

Source

pub fn checked_div(&self, rhs: &CBig) -> OxiNumResult<CBig>

Divides self by rhs without panicking.

Returns OxiNumError::DivByZero when rhs is zero; otherwise yields self / rhs computed as (self · conj(rhs)) / |rhs|².

This is the panic-free counterpart of the Div operator (which panics on a zero divisor, matching the rest of the workspace) and is the entry point sibling routines such as complex tan/tanh use.

§Examples
use oxinum_complex::CBig;

let a = CBig::from_f64(1.0, 1.0).expect("finite parts");
let q = a.checked_div(&a).expect("non-zero divisor");
assert_eq!(q.re().to_string(), "1");
assert_eq!(q.im().to_string(), "0");

assert!(a.checked_div(&CBig::zero()).is_err());
Source§

impl CBig

Source

pub fn abs(&self, precision: usize) -> OxiNumResult<DBig>

The magnitude |z| = sqrt(a² + b²) as a real DBig at precision significant digits.

Returns an exact decimal zero for a zero input (avoiding a sqrt(0) round trip). The squared magnitude is taken from CBig::norm_sqr.

§Errors

Propagates any error from oxinum_float::sqrt (none expected for the non-negative norm_sqr; an OxiNumError::Precision is returned if precision == 0).

Source

pub fn arg(&self, precision: usize) -> OxiNumResult<DBig>

The argument arg(z) = atan2(b, a) as a real DBig at precision significant digits, the principal value in (−π, π].

§Errors

Propagates any error from oxinum_float::atan2.

Source

pub fn exp(&self, precision: usize) -> OxiNumResult<CBig>

The complex exponential exp(z) = eᵃ·(cos b + i·sin b) at precision significant digits.

§Errors

Propagates errors from oxinum_float::exp, oxinum_float::cos, and oxinum_float::sin.

Source

pub fn ln(&self, precision: usize) -> OxiNumResult<CBig>

The principal complex logarithm ln(z) = ½·ln(a² + b²) + i·atan2(b, a) at precision significant digits.

Using ½·ln(norm_sqr) for the real part avoids an extra sqrt.

§Errors
Source

pub fn sqrt(&self, precision: usize) -> OxiNumResult<CBig>

The principal square root sqrt(z) at precision significant digits.

Uses re = sqrt((|z| + a)/2), im = sign(b)·sqrt((|z| − a)/2), with the purely-real input handled by an exact axis split and the radicands clamped up to zero before the real sqrt to absorb rounding noise. The branch chosen has re ≥ 0 and matches the IEEE-754 / num-complex principal value (so sqrt(-1) = +i).

§Errors

Propagates errors from oxinum_float::sqrt (none expected: radicands are clamped non-negative).

Source

pub fn pow(&self, w: &CBig, precision: usize) -> OxiNumResult<CBig>

The complex power z^w = exp(w · ln z) at precision significant digits.

The zero base is handled by convention: 0^0 = 1 and 0^w = 0 for any other w (avoiding ln(0)).

§Errors

Propagates errors from CBig::ln / CBig::exp.

Source§

impl CBig

Source

pub fn sin(&self, precision: usize) -> OxiNumResult<CBig>

The complex sine sin z = sin a · cosh b + i · cos a · sinh b at precision digits.

§Errors

Propagates errors from the real sin/cos/sinh/cosh routines.

Source

pub fn cos(&self, precision: usize) -> OxiNumResult<CBig>

The complex cosine cos z = cos a · cosh b − i · sin a · sinh b at precision digits.

§Errors

Propagates errors from the real sin/cos/sinh/cosh routines.

Source

pub fn sinh(&self, precision: usize) -> OxiNumResult<CBig>

The complex hyperbolic sine sinh z = sinh a · cos b + i · cosh a · sin b at precision digits.

§Errors

Propagates errors from the real sin/cos/sinh/cosh routines.

Source

pub fn cosh(&self, precision: usize) -> OxiNumResult<CBig>

The complex hyperbolic cosine cosh z = cosh a · cos b + i · sinh a · sin b at precision digits.

§Errors

Propagates errors from the real sin/cos/sinh/cosh routines.

Source

pub fn tan(&self, precision: usize) -> OxiNumResult<CBig>

The complex tangent tan z = sin z / cos z at precision digits.

§Errors
  • OxiNumError::DivByZero at the poles where cos z = 0.
  • Propagates errors from the real sin/cos/sinh/cosh routines.
Source

pub fn tanh(&self, precision: usize) -> OxiNumResult<CBig>

The complex hyperbolic tangent tanh z = sinh z / cosh z at precision digits.

§Errors
  • OxiNumError::DivByZero at the poles where cosh z = 0.
  • Propagates errors from the real sin/cos/sinh/cosh routines.
Source§

impl CBig

Source

pub fn new(re: DBig, im: DBig) -> Self

Construct a complex number from its real and imaginary parts.

Alias of CBig::from_parts.

Source

pub fn from_parts(re: DBig, im: DBig) -> Self

Construct a complex number from its real and imaginary parts.

Source

pub fn from_real(re: DBig) -> Self

Construct a purely real complex number (im = 0).

Source

pub fn from_imag(im: DBig) -> Self

Construct a purely imaginary complex number (re = 0).

Source

pub fn zero() -> Self

The additive identity 0 + 0·i.

Source

pub fn one() -> Self

The multiplicative identity 1 + 0·i.

Source

pub fn i() -> Self

The imaginary unit 0 + 1·i.

Source

pub fn from_f64(re: f64, im: f64) -> OxiNumResult<Self>

Construct a complex number from a pair of f64 values.

Each component is converted to DBig by formatting it with 17 significant digits (enough to round-trip any finite f64) and parsing the resulting string.

§Errors

Returns OxiNumError::Parse if either input is NaN or infinite (DBig models neither) or if the formatted decimal string fails to parse.

§Examples
use oxinum_complex::CBig;
let z = CBig::from_f64(1.5, -2.25).expect("finite parts");
assert_eq!(z.re().to_string(), "1.5");
assert_eq!(z.im().to_string(), "-2.25");
Source

pub fn re(&self) -> &DBig

A shared reference to the real part.

Source

pub fn im(&self) -> &DBig

A shared reference to the imaginary part.

Source

pub fn real(&self) -> DBig

A clone of the real part.

Source

pub fn imag(&self) -> DBig

A clone of the imaginary part.

Source

pub fn into_parts(self) -> (DBig, DBig)

Decompose into the owned (re, im) pair.

Source

pub fn conj(&self) -> Self

The complex conjugate re − im·i.

§Examples
use oxinum_complex::CBig;
let z = CBig::from_f64(2.0, 3.0).expect("finite parts");
let c = z.conj();
assert_eq!(c.re().to_string(), "2");
assert_eq!(c.im().to_string(), "-3");
Source

pub fn norm_sqr(&self) -> DBig

The squared magnitude re² + im² (always real, non-negative).

§Examples
use oxinum_complex::CBig;
let z = CBig::from_f64(3.0, 4.0).expect("finite parts");
assert_eq!(z.norm_sqr().to_string(), "25");
Source

pub fn is_zero(&self) -> bool

Returns true if both components are zero.

Source

pub fn is_real(&self) -> bool

Returns true if the imaginary part is zero (the value is real).

Source

pub fn is_imaginary(&self) -> bool

Returns true if the real part is zero (the value is purely imaginary).

Trait Implementations§

Source§

impl Add<&CBig> for &CBig

Source§

type Output = CBig

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &CBig) -> CBig

Performs the + operation. Read more
Source§

impl Add<&CBig> for CBig

Source§

type Output = CBig

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &CBig) -> CBig

Performs the + operation. Read more
Source§

impl Add<CBig> for &CBig

Source§

type Output = CBig

The resulting type after applying the + operator.
Source§

fn add(self, rhs: CBig) -> CBig

Performs the + operation. Read more
Source§

impl Add for CBig

Source§

type Output = CBig

The resulting type after applying the + operator.
Source§

fn add(self, rhs: CBig) -> CBig

Performs the + operation. Read more
Source§

impl AddAssign<&CBig> for CBig

Source§

fn add_assign(&mut self, rhs: &CBig)

Performs the += operation. Read more
Source§

impl AddAssign for CBig

Source§

fn add_assign(&mut self, rhs: CBig)

Performs the += operation. Read more
Source§

impl Clone for CBig

Source§

fn clone(&self) -> CBig

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 Debug for CBig

Developer-facing representation that names both components explicitly.

§Examples

use oxinum_complex::CBig;
let z = CBig::from_f64(2.0, -3.0).expect("finite parts");
assert_eq!(format!("{z:?}"), "CBig { re: 2, im: -3 }");
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CBig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for CBig

Render as "<re> + <im>i" when the imaginary part is non-negative, and "<re> - <|im|>i" when it is negative.

§Examples

use oxinum_complex::CBig;
let z = CBig::from_f64(2.0, 3.0).expect("finite parts");
assert_eq!(z.to_string(), "2 + 3i");
let w = CBig::from_f64(2.0, -3.0).expect("finite parts");
assert_eq!(w.to_string(), "2 - 3i");
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<&CBig> for &CBig

Source§

type Output = CBig

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &CBig) -> CBig

Performs the / operation. Read more
Source§

impl Div<&CBig> for CBig

Source§

type Output = CBig

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &CBig) -> CBig

Performs the / operation. Read more
Source§

impl Div<CBig> for &CBig

Source§

type Output = CBig

The resulting type after applying the / operator.
Source§

fn div(self, rhs: CBig) -> CBig

Performs the / operation. Read more
Source§

impl Div for CBig

Source§

type Output = CBig

The resulting type after applying the / operator.
Source§

fn div(self, rhs: CBig) -> CBig

Performs the / operation. Read more
Source§

impl DivAssign<&CBig> for CBig

Source§

fn div_assign(&mut self, rhs: &CBig)

Performs the /= operation. Read more
Source§

impl DivAssign for CBig

Source§

fn div_assign(&mut self, rhs: CBig)

Performs the /= operation. Read more
Source§

impl From<&FBig<HalfAway, 10>> for CBig

Embed a borrowed real DBig on the real axis (im = 0).

Source§

fn from(re: &DBig) -> Self

Converts to this type from the input type.
Source§

impl From<(FBig<HalfAway, 10>, FBig<HalfAway, 10>)> for CBig

Build a complex number from an explicit (re, im) pair of DBig values.

Source§

fn from((re, im): (DBig, DBig)) -> Self

Converts to this type from the input type.
Source§

impl From<(i64, i64)> for CBig

Build a complex number from an integer (re, im) pair (convenience).

Both parts are represented exactly (at unlimited DBig precision), so the result keeps full precision through later arithmetic — e.g. CBig::from((3, 4)).norm_sqr() is the exact 25. See the module-level “Integer conversions are exact” note for the rationale.

Source§

fn from((re, im): (i64, i64)) -> Self

Converts to this type from the input type.
Source§

impl From<FBig<HalfAway, 10>> for CBig

Embed a real DBig on the real axis (im = 0).

Source§

fn from(re: DBig) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for CBig

Embed an integer on the real axis (im = 0).

The real part is represented exactly (at unlimited DBig precision), so the value keeps full precision through later arithmetic. See the module-level “Integer conversions are exact” note for the rationale.

Source§

fn from(re: i64) -> Self

Converts to this type from the input type.
Source§

impl Mul<&CBig> for &CBig

Source§

type Output = CBig

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &CBig) -> CBig

Performs the * operation. Read more
Source§

impl Mul<&CBig> for CBig

Source§

type Output = CBig

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &CBig) -> CBig

Performs the * operation. Read more
Source§

impl Mul<CBig> for &CBig

Source§

type Output = CBig

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: CBig) -> CBig

Performs the * operation. Read more
Source§

impl Mul for CBig

Source§

type Output = CBig

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: CBig) -> CBig

Performs the * operation. Read more
Source§

impl MulAssign<&CBig> for CBig

Source§

fn mul_assign(&mut self, rhs: &CBig)

Performs the *= operation. Read more
Source§

impl MulAssign for CBig

Source§

fn mul_assign(&mut self, rhs: CBig)

Performs the *= operation. Read more
Source§

impl Neg for &CBig

Source§

type Output = CBig

The resulting type after applying the - operator.
Source§

fn neg(self) -> CBig

Performs the unary - operation. Read more
Source§

impl Neg for CBig

Source§

type Output = CBig

The resulting type after applying the - operator.
Source§

fn neg(self) -> CBig

Performs the unary - operation. Read more
Source§

impl PartialEq for CBig

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<&CBig> for &CBig

Source§

type Output = CBig

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &CBig) -> CBig

Performs the - operation. Read more
Source§

impl Sub<&CBig> for CBig

Source§

type Output = CBig

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &CBig) -> CBig

Performs the - operation. Read more
Source§

impl Sub<CBig> for &CBig

Source§

type Output = CBig

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: CBig) -> CBig

Performs the - operation. Read more
Source§

impl Sub for CBig

Source§

type Output = CBig

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: CBig) -> CBig

Performs the - operation. Read more
Source§

impl SubAssign<&CBig> for CBig

Source§

fn sub_assign(&mut self, rhs: &CBig)

Performs the -= operation. Read more
Source§

impl SubAssign for CBig

Source§

fn sub_assign(&mut self, rhs: CBig)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl Freeze for CBig

§

impl RefUnwindSafe for CBig

§

impl Send for CBig

§

impl Sync for CBig

§

impl Unpin for CBig

§

impl UnsafeUnpin for CBig

§

impl UnwindSafe for CBig

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.