Struct rug::complex::MiniComplex

source ·
pub struct MiniComplex { /* private fields */ }
Expand description

A small complex number that does not require any memory allocation.

This can be useful when you have real and imaginary numbers that are primitive integers or floats and you need a reference to a Complex.

The MiniComplex will have a precision according to the types of the primitives used to set its real and imaginary parts. Note that if different types are used to set the parts, the parts can have different precisions.

  • i8, u8: the part will have eight bits of precision.
  • i16, u16: the part will have 16 bits of precision.
  • i32, u32: the part will have 32 bits of precision.
  • i64, u64: the part will have 64 bits of precision.
  • i128, u128: the part will have 128 bits of precision.
  • isize, usize: the part will have 32 or 64 bits of precision, depending on the platform.
  • f32: the part will have 24 bits of precision.
  • f64: the part will have 53 bits of precision.
  • Special: the part will have the minimum possible precision.

The borrow method returns an object that can be coerced to a Complex, as it implements Deref<Target = Complex>.

Examples

use rug::complex::MiniComplex;
use rug::Complex;
// `a` requires a heap allocation
let mut a = Complex::with_val(53, (1, 2));
// `b` can reside on the stack
let b = MiniComplex::from((-10f64, -20.5f64));
a += &*b.borrow();
assert_eq!(*a.real(), -9);
assert_eq!(*a.imag(), -18.5);

Implementations§

source§

impl MiniComplex

source

pub const fn new() -> Self

Creates a MiniComplex with value 0 and the minimum possible precision.

Examples
use rug::complex::MiniComplex;
let c = MiniComplex::new();
// Borrow c as if it were Complex.
assert_eq!(*c.borrow(), 0);
source

pub unsafe fn as_nonreallocating_complex(&mut self) -> &mut Complex

Returns a mutable reference to a Complex number for simple operations that do not need to change the precision of the real or imaginary part.

Safety

It is undefined behavior to modify the precision of the referenced Complex number or to swap it with another number.

Examples
use rug::complex::MiniComplex;
let mut c = MiniComplex::from((1.0f32, 3.0f32));
// rotation does not change the precision
unsafe {
    c.as_nonreallocating_complex().mul_i_mut(false);
}
assert_eq!(*c.borrow(), (-3.0, 1.0));
source

pub fn borrow(&self) -> impl Deref<Target = Complex> + '_

Borrows the complex number.

The returned object implements Deref<Target = Complex>.

The borrow lasts until the returned object exits scope. Multiple borrows can be taken at the same time.

Examples
use rug::complex::MiniComplex;
use rug::Complex;
let c = MiniComplex::from((-13f64, 5.5f64));
let b = c.borrow();
let conj = Complex::with_val(53, b.conj_ref());
assert_eq!(*conj.real(), -13);
assert_eq!(*conj.imag(), -5.5);
source

pub fn borrow_excl(&mut self) -> &Complex

Borrows the complex number exclusively.

This is similar to the borrow method, but it requires exclusive access to the underlying MiniComplex; the returned reference can however be shared. The exclusive access is required to reduce the amount of housekeeping necessary, providing a more efficient operation.

Examples
use rug::complex::MiniComplex;
use rug::Complex;
let mut c = MiniComplex::from((-13f64, 5.5f64));
let b = c.borrow_excl();
let conj = Complex::with_val(53, b.conj_ref());
assert_eq!(*conj.real(), -13);
assert_eq!(*conj.imag(), -5.5);

Trait Implementations§

source§

impl Assign<&MiniComplex> for MiniComplex

source§

fn assign(&mut self, other: &Self)

Peforms the assignement.
source§

impl<Re: ToMini, Im: ToMini> Assign<(Re, Im)> for MiniComplex

source§

fn assign(&mut self, src: (Re, Im))

Peforms the assignement.
source§

impl<Re: ToMini> Assign<Re> for MiniComplex

source§

fn assign(&mut self, src: Re)

Peforms the assignement.
source§

impl Assign for MiniComplex

source§

fn assign(&mut self, other: Self)

Peforms the assignement.
source§

impl AssignRound<&MiniComplex> for Complex

§

type Round = (Round, Round)

The rounding method.
§

type Ordering = (Ordering, Ordering)

The direction from rounding.
source§

fn assign_round( &mut self, src: &MiniComplex, round: (Round, Round) ) -> (Ordering, Ordering)

Peforms the assignment. Read more
source§

impl AssignRound<MiniComplex> for Complex

§

type Round = (Round, Round)

The rounding method.
§

type Ordering = (Ordering, Ordering)

The direction from rounding.
source§

fn assign_round( &mut self, src: MiniComplex, round: (Round, Round) ) -> (Ordering, Ordering)

Peforms the assignment. Read more
source§

impl Binary for MiniComplex

source§

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

Formats the value using the given formatter.
source§

impl Clone for MiniComplex

source§

fn clone(&self) -> MiniComplex

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for MiniComplex

source§

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

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

impl Default for MiniComplex

source§

fn default() -> Self

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

impl Display for MiniComplex

source§

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

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

impl<Re: ToMini, Im: ToMini> From<(Re, Im)> for MiniComplex

source§

fn from(src: (Re, Im)) -> Self

Converts to this type from the input type.
source§

impl<Re: ToMini> From<Re> for MiniComplex

source§

fn from(src: Re) -> Self

Converts to this type from the input type.
source§

impl LowerExp for MiniComplex

source§

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

Formats the value using the given formatter.
source§

impl LowerHex for MiniComplex

source§

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

Formats the value using the given formatter.
source§

impl Octal for MiniComplex

source§

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

Formats the value using the given formatter.
source§

impl PartialEq<Complex> for MiniComplex

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<MiniComplex> for Complex

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl UpperExp for MiniComplex

source§

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

Formats the value using the given formatter.
source§

impl UpperHex for MiniComplex

source§

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

Formats the value using the given formatter.
source§

impl Copy for MiniComplex

source§

impl Send for MiniComplex

source§

impl Sync for MiniComplex

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> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

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

§

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§

default 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>,

§

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

§

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.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.