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
impl CBig
Sourcepub fn to_f64_parts(&self) -> (f64, f64)
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
impl CBig
Sourcepub fn checked_div(&self, rhs: &CBig) -> OxiNumResult<CBig>
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
impl CBig
Sourcepub fn abs(&self, precision: usize) -> OxiNumResult<DBig>
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).
Sourcepub fn arg(&self, precision: usize) -> OxiNumResult<DBig>
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.
Sourcepub fn exp(&self, precision: usize) -> OxiNumResult<CBig>
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.
Sourcepub fn ln(&self, precision: usize) -> OxiNumResult<CBig>
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
OxiNumError::Domainifzis zero (ln(0)is undefined).- Propagates errors from
oxinum_float::ln/oxinum_float::atan2.
Sourcepub fn sqrt(&self, precision: usize) -> OxiNumResult<CBig>
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§impl CBig
impl CBig
Sourcepub fn sin(&self, precision: usize) -> OxiNumResult<CBig>
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.
Sourcepub fn cos(&self, precision: usize) -> OxiNumResult<CBig>
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.
Sourcepub fn sinh(&self, precision: usize) -> OxiNumResult<CBig>
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.
Sourcepub fn cosh(&self, precision: usize) -> OxiNumResult<CBig>
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.
Sourcepub fn tan(&self, precision: usize) -> OxiNumResult<CBig>
pub fn tan(&self, precision: usize) -> OxiNumResult<CBig>
The complex tangent tan z = sin z / cos z at precision digits.
§Errors
OxiNumError::DivByZeroat the poles wherecos z = 0.- Propagates errors from the real
sin/cos/sinh/coshroutines.
Sourcepub fn tanh(&self, precision: usize) -> OxiNumResult<CBig>
pub fn tanh(&self, precision: usize) -> OxiNumResult<CBig>
The complex hyperbolic tangent tanh z = sinh z / cosh z at
precision digits.
§Errors
OxiNumError::DivByZeroat the poles wherecosh z = 0.- Propagates errors from the real
sin/cos/sinh/coshroutines.
Source§impl CBig
impl CBig
Sourcepub fn new(re: DBig, im: DBig) -> Self
pub fn new(re: DBig, im: DBig) -> Self
Construct a complex number from its real and imaginary parts.
Alias of CBig::from_parts.
Sourcepub fn from_parts(re: DBig, im: DBig) -> Self
pub fn from_parts(re: DBig, im: DBig) -> Self
Construct a complex number from its real and imaginary parts.
Sourcepub fn from_f64(re: f64, im: f64) -> OxiNumResult<Self>
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");Sourcepub fn into_parts(self) -> (DBig, DBig)
pub fn into_parts(self) -> (DBig, DBig)
Decompose into the owned (re, im) pair.
Sourcepub fn conj(&self) -> Self
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");Sourcepub fn norm_sqr(&self) -> DBig
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");Sourcepub fn is_imaginary(&self) -> bool
pub fn is_imaginary(&self) -> bool
Returns true if the real part is zero (the value is purely imaginary).
Trait Implementations§
Source§impl AddAssign<&CBig> for CBig
impl AddAssign<&CBig> for CBig
Source§fn add_assign(&mut self, rhs: &CBig)
fn add_assign(&mut self, rhs: &CBig)
+= operation. Read moreSource§impl AddAssign for CBig
impl AddAssign for CBig
Source§fn add_assign(&mut self, rhs: CBig)
fn add_assign(&mut self, rhs: CBig)
+= operation. Read moreSource§impl Debug for CBig
Developer-facing representation that names both components explicitly.
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§impl Display for CBig
Render as "<re> + <im>i" when the imaginary part is non-negative, and
"<re> - <|im|>i" when it is negative.
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§impl DivAssign<&CBig> for CBig
impl DivAssign<&CBig> for CBig
Source§fn div_assign(&mut self, rhs: &CBig)
fn div_assign(&mut self, rhs: &CBig)
/= operation. Read moreSource§impl DivAssign for CBig
impl DivAssign for CBig
Source§fn div_assign(&mut self, rhs: CBig)
fn div_assign(&mut self, rhs: CBig)
/= operation. Read moreSource§impl From<(FBig<HalfAway, 10>, FBig<HalfAway, 10>)> for CBig
Build a complex number from an explicit (re, im) pair of DBig values.
impl From<(FBig<HalfAway, 10>, FBig<HalfAway, 10>)> for CBig
Build a complex number from an explicit (re, im) pair of DBig values.
Source§impl From<(i64, i64)> for CBig
Build a complex number from an integer (re, im) pair (convenience).
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§impl From<i64> for CBig
Embed an integer on the real axis (im = 0).
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§impl MulAssign<&CBig> for CBig
impl MulAssign<&CBig> for CBig
Source§fn mul_assign(&mut self, rhs: &CBig)
fn mul_assign(&mut self, rhs: &CBig)
*= operation. Read moreSource§impl MulAssign for CBig
impl MulAssign for CBig
Source§fn mul_assign(&mut self, rhs: CBig)
fn mul_assign(&mut self, rhs: CBig)
*= operation. Read more