Skip to main content

BigComplex

Struct BigComplex 

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

Native arbitrary-precision binary complex number re + im·i.

Both components are BigFloat values. See the module-level documentation for the rationale behind the absence of Hash, Eq, and Ord.

§Examples

use oxinum_complex::native::{BigComplex, RoundingMode};

let z = BigComplex::from_f64(3.0, 4.0, 53).expect("finite parts");
// |3 + 4i|^2 = 25.
assert_eq!(z.norm_sqr().to_f64(), 25.0);

Implementations§

Source§

impl BigComplex

Source

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

Construct a complex number from its real and imaginary parts.

Source

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

Construct a complex number from its real and imaginary parts.

Alias of BigComplex::from_parts.

Source

pub fn from_real(re: BigFloat) -> Self

Construct a purely real complex number (im = 0 at re’s precision).

Source

pub fn from_imag(im: BigFloat) -> Self

Construct a purely imaginary complex number (re = 0 at im’s precision).

Source

pub fn zero(prec: u32) -> Self

The additive identity 0 + 0·i at prec bits of precision.

Source

pub fn one(prec: u32, mode: RoundingMode) -> Self

The multiplicative identity 1 + 0·i at prec bits of precision.

Source

pub fn i(prec: u32, mode: RoundingMode) -> Self

The imaginary unit 0 + 1·i at prec bits of precision.

Source

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

Construct a complex number from a pair of f64 values at prec bits.

Delegates to BigFloat::from_f64 for each component.

§Errors

Propagates the OxiNumError returned by BigFloat::from_f64 when a component is NaN or infinite — the native BigFloat rejects those inputs.

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

pub fn re(&self) -> &BigFloat

A shared reference to the real part.

Source

pub fn im(&self) -> &BigFloat

A shared reference to the imaginary part.

Source

pub fn real(&self) -> BigFloat

A clone of the real part.

Source

pub fn imag(&self) -> BigFloat

A clone of the imaginary part.

Source

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

Decompose into the owned (re, im) pair.

Source

pub fn conj(&self) -> Self

The complex conjugate re − im·i.

§Examples
use oxinum_complex::native::BigComplex;
let z = BigComplex::from_f64(2.0, 3.0, 53).expect("finite parts");
let c = z.conj();
assert_eq!(c.re().to_f64(), 2.0);
assert_eq!(c.im().to_f64(), -3.0);
Source

pub fn norm_sqr(&self) -> BigFloat

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

§Examples
use oxinum_complex::native::BigComplex;
let z = BigComplex::from_f64(3.0, 4.0, 53).expect("finite parts");
assert_eq!(z.norm_sqr().to_f64(), 25.0);
Source

pub fn is_zero(&self) -> bool

Returns true if both components are the canonical zero.

Source§

impl BigComplex

Source

pub fn checked_div( &self, rhs: &BigComplex, prec: u32, mode: RoundingMode, ) -> OxiNumResult<BigComplex>

Checked complex division self / rhs at prec bits.

This is the public, no-panic division entry point for native complex values (there is deliberately no core::ops::Div impl — see the module docs). The result components are rounded to prec bits with mode.

§Errors

Returns OxiNumError::DivByZero if rhs is zero.

§Examples
use oxinum_complex::native::{BigComplex, RoundingMode};
// (2 + 0i) / (1 + i) = 1 − i.
let num = BigComplex::from_f64(2.0, 0.0, 80).expect("finite");
let den = BigComplex::from_f64(1.0, 1.0, 80).expect("finite");
let q = num
    .checked_div(&den, 80, RoundingMode::HalfEven)
    .expect("non-zero divisor");
assert!((q.re().to_f64() - 1.0).abs() < 1e-12);
assert!((q.im().to_f64() + 1.0).abs() < 1e-12);
Source§

impl BigComplex

Source

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

Project to a pair of f64s (re, im) via BigFloat::to_f64.

This is a lossy convenience conversion: each component is rounded to the nearest f64 (and non-finite components map to the corresponding f64::NAN / f64::INFINITY, matching BigFloat::to_f64).

§Examples
use oxinum_complex::native::BigComplex;
let z = BigComplex::from_f64(1.5, -2.25, 80).expect("finite");
let (re, im) = z.to_f64_parts();
assert_eq!(re, 1.5);
assert_eq!(im, -2.25);
Source§

impl BigComplex

Source

pub fn abs(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>

The magnitude |z| = sqrt(a² + b²) as a real BigFloat at prec bits.

Returns the canonical zero for a zero input (avoiding a sqrt(0) round trip). The squared magnitude is taken from BigComplex::norm_sqr.

§Errors

Propagates any error from BigFloat::sqrt (none expected for the non-negative norm_sqr).

§Examples
use oxinum_complex::native::{BigComplex, RoundingMode};
let z = BigComplex::from_f64(3.0, 4.0, 80).expect("finite");
let m = z.abs(80, RoundingMode::HalfEven).expect("abs");
assert!((m.to_f64() - 5.0).abs() < 1e-12);
Source

pub fn arg(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>

The argument arg(z) = atan2(b, a) as a real BigFloat at prec bits, the principal value in (−π, π].

§Errors

Propagates any error from BigFloat::atan2.

§Examples
use oxinum_complex::native::{BigComplex, RoundingMode};
let i = BigComplex::i(80, RoundingMode::HalfEven);
let a = i.arg(80, RoundingMode::HalfEven).expect("arg");
assert!((a.to_f64() - std::f64::consts::FRAC_PI_2).abs() < 1e-12);
Source

pub fn exp(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigComplex>

The complex exponential exp(z) = eᵃ·(cos b + i·sin b) at prec bits.

§Errors

Propagates errors from BigFloat::exp (e.g. overflow when a is huge) and from the real trig routines.

§Examples
use oxinum_complex::native::{BigComplex, RoundingMode};
// exp(iπ) ≈ −1 + 0i  (Euler's identity).
let z = BigComplex::from_f64(0.0, std::f64::consts::PI, 80).expect("finite");
let e = z.exp(80, RoundingMode::HalfEven).expect("exp");
assert!((e.re().to_f64() + 1.0).abs() < 1e-12);
assert!(e.im().to_f64().abs() < 1e-12);
Source

pub fn ln(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigComplex>

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

§Errors
§Examples
use oxinum_complex::native::{BigComplex, RoundingMode};
// ln(−1) ≈ 0 + iπ.
let z = BigComplex::from_f64(-1.0, 0.0, 80).expect("finite");
let l = z.ln(80, RoundingMode::HalfEven).expect("ln");
assert!(l.re().to_f64().abs() < 1e-12);
assert!((l.im().to_f64() - std::f64::consts::PI).abs() < 1e-12);
Source

pub fn sqrt(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigComplex>

The principal square root sqrt(z) at prec bits.

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.

§Errors

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

§Examples
use oxinum_complex::native::{BigComplex, RoundingMode};
// sqrt(2i) = 1 + i.
let z = BigComplex::from_f64(0.0, 2.0, 80).expect("finite");
let r = z.sqrt(80, RoundingMode::HalfEven).expect("sqrt");
assert!((r.re().to_f64() - 1.0).abs() < 1e-12);
assert!((r.im().to_f64() - 1.0).abs() < 1e-12);
Source

pub fn pow( &self, w: &BigComplex, prec: u32, mode: RoundingMode, ) -> OxiNumResult<BigComplex>

The complex power z^w = exp(w · ln z) at prec bits.

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 BigComplex::ln / BigComplex::exp.

§Examples
use oxinum_complex::native::{BigComplex, RoundingMode};
// i^2 = −1.
let i = BigComplex::i(80, RoundingMode::HalfEven);
let two = BigComplex::from_f64(2.0, 0.0, 80).expect("finite");
let r = i.pow(&two, 80, RoundingMode::HalfEven).expect("pow");
assert!((r.re().to_f64() + 1.0).abs() < 1e-12);
assert!(r.im().to_f64().abs() < 1e-12);
Source§

impl BigComplex

Source

pub fn sin(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigComplex>

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

§Errors

Propagates errors from the real sin/cos/exp routines.

§Examples
use oxinum_complex::native::{BigComplex, RoundingMode};
let s = BigComplex::zero(80).sin(80, RoundingMode::HalfEven).expect("sin");
assert!(s.re().to_f64().abs() < 1e-12);
assert!(s.im().to_f64().abs() < 1e-12);
Source

pub fn cos(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigComplex>

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

§Errors

Propagates errors from the real sin/cos/exp routines.

§Examples
use oxinum_complex::native::{BigComplex, RoundingMode};
let c = BigComplex::zero(80).cos(80, RoundingMode::HalfEven).expect("cos");
assert!((c.re().to_f64() - 1.0).abs() < 1e-12);
assert!(c.im().to_f64().abs() < 1e-12);
Source

pub fn sinh(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigComplex>

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

§Errors

Propagates errors from the real sin/cos/exp routines.

Source

pub fn cosh(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigComplex>

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

§Errors

Propagates errors from the real sin/cos/exp routines.

§Examples
use oxinum_complex::native::{BigComplex, RoundingMode};
let c = BigComplex::zero(80).cosh(80, RoundingMode::HalfEven).expect("cosh");
assert!((c.re().to_f64() - 1.0).abs() < 1e-12);
assert!(c.im().to_f64().abs() < 1e-12);
Source

pub fn tan(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigComplex>

The complex tangent tan z = sin z / cos z at prec bits.

§Errors
Source

pub fn tanh(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigComplex>

The complex hyperbolic tangent tanh z = sinh z / cosh z at prec bits.

§Errors

Trait Implementations§

Source§

impl Add<&BigComplex> for &BigComplex

Source§

type Output = BigComplex

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<&BigComplex> for BigComplex

Source§

type Output = BigComplex

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<BigComplex> for &BigComplex

Source§

type Output = BigComplex

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for BigComplex

Source§

type Output = BigComplex

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign<&BigComplex> for BigComplex

Source§

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

Performs the += operation. Read more
Source§

impl AddAssign for BigComplex

Source§

fn add_assign(&mut self, rhs: BigComplex)

Performs the += operation. Read more
Source§

impl Clone for BigComplex

Source§

fn clone(&self) -> BigComplex

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 BigComplex

Source§

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

Structural debug view exposing the real and imaginary [BigFloat]s.

Source§

impl Display for BigComplex

Source§

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

Format as a + bi (or a - bi when the imaginary part is negative).

Each component is delegated to BigFloat’s Display. The real part keeps its own sign; the imaginary part is shown as a magnitude with an explicit +/- separator chosen from its sign.

§Examples
use oxinum_complex::native::BigComplex;
let z = BigComplex::from_f64(1.0, -2.0, 53).expect("finite");
let s = format!("{z}");
assert!(s.contains('-'));
assert!(s.ends_with('i'));
Source§

impl From<(BigFloat, BigFloat)> for BigComplex

Source§

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

Build re + im·i from the ordered pair (re, im).

Source§

impl From<BigFloat> for BigComplex

Source§

fn from(re: BigFloat) -> Self

Place a real BigFloat on the real axis (im = 0 at re’s precision).

Source§

impl Mul<&BigComplex> for &BigComplex

Source§

type Output = BigComplex

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<&BigComplex> for BigComplex

Source§

type Output = BigComplex

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<BigComplex> for &BigComplex

Source§

type Output = BigComplex

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul for BigComplex

Source§

type Output = BigComplex

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign<&BigComplex> for BigComplex

Source§

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

Performs the *= operation. Read more
Source§

impl MulAssign for BigComplex

Source§

fn mul_assign(&mut self, rhs: BigComplex)

Performs the *= operation. Read more
Source§

impl Neg for &BigComplex

Source§

type Output = BigComplex

The resulting type after applying the - operator.
Source§

fn neg(self) -> BigComplex

Performs the unary - operation. Read more
Source§

impl Neg for BigComplex

Source§

type Output = BigComplex

The resulting type after applying the - operator.
Source§

fn neg(self) -> BigComplex

Performs the unary - operation. Read more
Source§

impl PartialEq for BigComplex

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<&BigComplex> for &BigComplex

Source§

type Output = BigComplex

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<&BigComplex> for BigComplex

Source§

type Output = BigComplex

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<BigComplex> for &BigComplex

Source§

type Output = BigComplex

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub for BigComplex

Source§

type Output = BigComplex

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign<&BigComplex> for BigComplex

Source§

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

Performs the -= operation. Read more
Source§

impl SubAssign for BigComplex

Source§

fn sub_assign(&mut self, rhs: BigComplex)

Performs the -= operation. Read more

Auto Trait Implementations§

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.