logo
#[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, float::Special, 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

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

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

Converts this type into a mutable reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Casts the value.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Casts the value.

Casts the value.

Casts the value.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Casts the value.

OverflowingCasts the value.

Casts the value.

Casts the value.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Casts the value.

UnwrappedCasts the value.

Casts the value.

WrappingCasts the value.