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
sourceimpl OrdComplex
impl OrdComplex
sourcepub fn as_complex(&self) -> &Complex
pub 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
sourceimpl AsMut<Complex> for OrdComplex
impl AsMut<Complex> for OrdComplex
sourceimpl AsRef<Complex> for OrdComplex
impl AsRef<Complex> for OrdComplex
sourceimpl AsRef<OrdComplex> for Complex
impl AsRef<OrdComplex> for Complex
sourcefn as_ref(&self) -> &OrdComplex
fn as_ref(&self) -> &OrdComplex
Converts this type into a shared reference of the (usually inferred) input type.
sourceimpl Clone for OrdComplex
impl Clone for OrdComplex
sourcefn clone(&self) -> OrdComplex
fn clone(&self) -> OrdComplex
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl Debug for OrdComplex
impl Debug for OrdComplex
sourceimpl<'de> Deserialize<'de> for OrdComplex
impl<'de> Deserialize<'de> for OrdComplex
sourcefn 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
sourceimpl From<Complex> for OrdComplex
impl From<Complex> for OrdComplex
sourceimpl From<OrdComplex> for Complex
impl From<OrdComplex> for Complex
sourcefn from(src: OrdComplex) -> Self
fn from(src: OrdComplex) -> Self
Converts to this type from the input type.
sourceimpl Hash for OrdComplex
impl Hash for OrdComplex
sourceimpl Ord for OrdComplex
impl Ord for OrdComplex
sourcefn cmp(&self, other: &OrdComplex) -> Ordering
fn cmp(&self, other: &OrdComplex) -> Ordering
1.21.0 · sourcefn 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
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<OrdComplex> for OrdComplex
impl PartialEq<OrdComplex> for OrdComplex
sourcefn eq(&self, other: &OrdComplex) -> bool
fn eq(&self, other: &OrdComplex) -> bool
sourceimpl PartialOrd<OrdComplex> for OrdComplex
impl PartialOrd<OrdComplex> for OrdComplex
sourcefn partial_cmp(&self, other: &OrdComplex) -> Option<Ordering>
fn partial_cmp(&self, other: &OrdComplex) -> Option<Ordering>
1.0.0 · sourcefn 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 moresourceimpl 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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedAs for T
impl<T> CheckedAs for T
sourcefn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
sourcefn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
sourceimpl<T> OverflowingAs for T
impl<T> OverflowingAs for T
sourcefn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
sourcefn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
sourceimpl<T> SaturatingAs for T
impl<T> SaturatingAs for T
sourcefn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
sourcefn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
sourcefn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
sourcefn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> WrappingAs for T
impl<T> WrappingAs for T
sourcefn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
sourcefn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.