Struct rug::complex::OrdComplex
source · #[repr(transparent)]pub struct OrdComplex { /* private fields */ }
Expand description
A complex number that supports total ordering and hashing.
For ordering, the real part has precedence over the imaginary part. Negative zero is ordered as less than positive zero. Negative NaN is ordered as less than negative infinity, while positive NaN is ordered as greater than positive infinity. Comparing two negative NaNs or two positive NaNs produces equality.
Examples
use core::cmp::Ordering;
use rug::complex::OrdComplex;
use rug::float::Special;
use rug::Complex;
let nan_c = Complex::with_val(53, (Special::Nan, Special::Nan));
let nan = OrdComplex::from(nan_c);
assert_eq!(nan.cmp(&nan), Ordering::Equal);
let one_neg0_c = Complex::with_val(53, (1, Special::NegZero));
let one_neg0 = OrdComplex::from(one_neg0_c);
let one_pos0_c = Complex::with_val(53, (1, Special::Zero));
let one_pos0 = OrdComplex::from(one_pos0_c);
assert_eq!(one_neg0.cmp(&one_pos0), Ordering::Less);
let zero_inf_s = (Special::Zero, Special::Infinity);
let zero_inf_c = Complex::with_val(53, zero_inf_s);
let zero_inf = OrdComplex::from(zero_inf_c);
assert_eq!(one_pos0.cmp(&zero_inf), Ordering::Greater);
Implementations§
source§impl OrdComplex
impl OrdComplex
sourcepub const fn as_complex(&self) -> &Complex
pub const fn as_complex(&self) -> &Complex
Extracts the underlying Complex
.
The same result can be obtained using the implementation of
AsRef<Complex>
which is provided for OrdComplex
.
Examples
use rug::complex::OrdComplex;
use rug::Complex;
let c = Complex::with_val(53, (1.5, 2.5));
let ord = OrdComplex::from(c);
let c_ref = ord.as_complex();
assert_eq!(*c_ref.real(), 1.5);
assert_eq!(*c_ref.imag(), 2.5);
sourcepub fn as_complex_mut(&mut self) -> &mut Complex
pub fn as_complex_mut(&mut self) -> &mut Complex
Extracts the underlying Complex
.
The same result can be obtained using the implementation of
AsMut<Complex>
which is provided for OrdComplex
.
Examples
use rug::complex::OrdComplex;
use rug::Complex;
let c = Complex::with_val(53, (1.5, -2.5));
let mut ord = OrdComplex::from(c);
ord.as_complex_mut().conj_mut();
let c_ref = ord.as_complex();
assert_eq!(*c_ref.real(), 1.5);
assert_eq!(*c_ref.imag(), 2.5);
Trait Implementations§
source§impl AsMut<Complex> for OrdComplex
impl AsMut<Complex> for OrdComplex
source§impl AsRef<Complex> for OrdComplex
impl AsRef<Complex> for OrdComplex
source§impl AsRef<OrdComplex> for Complex
impl AsRef<OrdComplex> for Complex
source§fn as_ref(&self) -> &OrdComplex
fn as_ref(&self) -> &OrdComplex
Converts this type into a shared reference of the (usually inferred) input type.
source§impl Clone for OrdComplex
impl Clone for OrdComplex
source§fn clone(&self) -> OrdComplex
fn clone(&self) -> OrdComplex
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for OrdComplex
impl Debug for OrdComplex
source§impl<'de> Deserialize<'de> for OrdComplex
impl<'de> Deserialize<'de> for OrdComplex
source§fn deserialize<D: Deserializer<'de>>(
deserializer: D
) -> Result<OrdComplex, D::Error>
fn deserialize<D: Deserializer<'de>>( deserializer: D ) -> Result<OrdComplex, D::Error>
Deserialize this value from the given Serde deserializer. Read more
source§impl From<Complex> for OrdComplex
impl From<Complex> for OrdComplex
source§impl From<OrdComplex> for Complex
impl From<OrdComplex> for Complex
source§fn from(src: OrdComplex) -> Self
fn from(src: OrdComplex) -> Self
Converts to this type from the input type.
source§impl Hash for OrdComplex
impl Hash for OrdComplex
source§impl Ord for OrdComplex
impl Ord for OrdComplex
source§fn cmp(&self, other: &OrdComplex) -> Ordering
fn cmp(&self, other: &OrdComplex) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<OrdComplex> for OrdComplex
impl PartialEq<OrdComplex> for OrdComplex
source§fn eq(&self, other: &OrdComplex) -> bool
fn eq(&self, other: &OrdComplex) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<OrdComplex> for OrdComplex
impl PartialOrd<OrdComplex> for OrdComplex
source§fn partial_cmp(&self, other: &OrdComplex) -> Option<Ordering>
fn partial_cmp(&self, other: &OrdComplex) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl Serialize for OrdComplex
impl Serialize for OrdComplex
impl Eq for OrdComplex
Auto Trait Implementations§
impl RefUnwindSafe for OrdComplex
impl Send for OrdComplex
impl Sync for OrdComplex
impl Unpin for OrdComplex
impl UnwindSafe for OrdComplex
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,
Casts the value.
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,
Casts the value.
source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,
source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,
Casts the value.
source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,
source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,
Casts the value.
source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,
source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,
Casts the value.
source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,
source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.