pub struct Relaxed(/* private fields */);
Expand description
An arbitrary precision rational number without strict reduction.
This struct is almost the same as RBig, except for that the numerator and the denominator are allowed to have common divisors other than a power of 2. This allows faster computation because Gcd is not required for each operation.
Since the representation is not canonicalized, Hash is not implemented for Relaxed.
Please use RBig if you want to store the rational number in a hash set, or use num_order::NumHash
.
§Conversion from/to RBig
To convert from RBig, use RBig::relax(). To convert to RBig, use Relaxed::canonicalize().
Implementations§
Source§impl Relaxed
impl Relaxed
Sourcepub fn to_f32_fast(&self) -> f32
pub fn to_f32_fast(&self) -> f32
Convert the rational number to a f32.
See RBig::to_f32_fast for details.
Sourcepub fn to_f64_fast(&self) -> f64
pub fn to_f64_fast(&self) -> f64
Convert the rational number to a f64.
See RBig::to_f64_fast for details.
Sourcepub fn to_f32(&self) -> Approximation<f32, Sign>
pub fn to_f32(&self) -> Approximation<f32, Sign>
Convert the rational number to a f32 with guaranteed correct rounding.
See RBig::to_f32 for details.
Sourcepub fn to_f64(&self) -> Approximation<f64, Sign>
pub fn to_f64(&self) -> Approximation<f64, Sign>
Convert the rational number to a f64 with guaranteed correct rounding.
See RBig::to_f64 for details.
Sourcepub fn to_int(&self) -> Approximation<IBig, Self>
pub fn to_int(&self) -> Approximation<IBig, Self>
Convert the rational number to am IBig.
See RBig::to_int for details.
Source§impl Relaxed
impl Relaxed
Source§impl Relaxed
impl Relaxed
Sourcepub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseError>
pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseError>
Convert a string in a given base to Relaxed.
See RBig::from_str_radix for details.
Sourcepub fn from_str_with_radix_prefix(src: &str) -> Result<(Self, u32), ParseError>
pub fn from_str_with_radix_prefix(src: &str) -> Result<(Self, u32), ParseError>
Convert a string with optional radix prefixes to RBig, return the parsed integer and radix.
See RBig::from_str_with_radix_prefix for details.
Source§impl Relaxed
impl Relaxed
Sourcepub fn from_parts(numerator: IBig, denominator: UBig) -> Self
pub fn from_parts(numerator: IBig, denominator: UBig) -> Self
Create a rational number from a signed numerator and a signed denominator
See RBig::from_parts for details.
Sourcepub fn into_parts(self) -> (IBig, UBig)
pub fn into_parts(self) -> (IBig, UBig)
Convert the rational number into (numerator, denumerator) parts.
See RBig::into_parts for details.
Sourcepub fn from_parts_signed(numerator: IBig, denominator: IBig) -> Self
pub fn from_parts_signed(numerator: IBig, denominator: IBig) -> Self
Create a rational number from a signed numerator and a signed denominator
See RBig::from_parts_signed for details.
Sourcepub const fn from_parts_const(
sign: Sign,
numerator: DoubleWord,
denominator: DoubleWord,
) -> Self
pub const fn from_parts_const( sign: Sign, numerator: DoubleWord, denominator: DoubleWord, ) -> Self
Create a rational number in a const context
See RBig::from_parts_const for details.
Sourcepub fn numerator(&self) -> &IBig
pub fn numerator(&self) -> &IBig
Get the numerator of the rational number
See RBig::numerator for details.
Sourcepub fn denominator(&self) -> &UBig
pub fn denominator(&self) -> &UBig
Get the denominator of the rational number
See RBig::denominator for details.
Sourcepub fn canonicalize(self) -> RBig
pub fn canonicalize(self) -> RBig
Sourcepub const fn is_zero(&self) -> bool
pub const fn is_zero(&self) -> bool
Check whether the number is 0
See RBig::is_zero for details.
Sourcepub fn is_one(&self) -> bool
pub fn is_one(&self) -> bool
Check whether the number is 1
See RBig::is_one for details.
Source§impl Relaxed
impl Relaxed
Sourcepub fn split_at_point(self) -> (IBig, Self)
pub fn split_at_point(self) -> (IBig, Self)
Split the rational number into integral and fractional parts (split at the radix point).
See RBig::split_at_point for details.
Sourcepub fn ceil(&self) -> IBig
pub fn ceil(&self) -> IBig
Compute the smallest integer that is greater than this number.
See RBig::ceil for details.
Sourcepub fn floor(&self) -> IBig
pub fn floor(&self) -> IBig
Compute the largest integer that is less than or equal to this number.
See RBig::floor for details.
Sourcepub fn round(&self) -> IBig
pub fn round(&self) -> IBig
Compute the integer that closest to this number.
See RBig::round for details.
Sourcepub fn trunc(&self) -> IBig
pub fn trunc(&self) -> IBig
Returns the integral part of the rational number.
See RBig::trunc for details.
Sourcepub fn fract(&self) -> Self
pub fn fract(&self) -> Self
Returns the fractional part of the rational number
See RBig::fract for details.
Source§impl Relaxed
impl Relaxed
Sourcepub const fn sign(&self) -> Sign
pub const fn sign(&self) -> Sign
Get the sign of the number. Zero value has a positive sign.
See RBig::sign for details.
Sourcepub const fn signum(&self) -> Self
pub const fn signum(&self) -> Self
A number representing the sign of self
.
See RBig::signum for details.
Trait Implementations§
Source§impl AddAssign<&Relaxed> for Relaxed
impl AddAssign<&Relaxed> for Relaxed
Source§fn add_assign(&mut self, rhs: &Relaxed)
fn add_assign(&mut self, rhs: &Relaxed)
+=
operation. Read moreSource§impl AddAssign for Relaxed
impl AddAssign for Relaxed
Source§fn add_assign(&mut self, rhs: Relaxed)
fn add_assign(&mut self, rhs: Relaxed)
+=
operation. Read moreSource§impl<'de> Deserialize<'de> for Relaxed
impl<'de> Deserialize<'de> for Relaxed
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Distribution<Relaxed> for Open01
impl Distribution<Relaxed> for Open01
Source§impl Distribution<Relaxed> for OpenClosed01
impl Distribution<Relaxed> for OpenClosed01
Source§impl Distribution<Relaxed> for Standard
impl Distribution<Relaxed> for Standard
Source§impl<'a> Distribution<Relaxed> for Uniform01<'a>
impl<'a> Distribution<Relaxed> for Uniform01<'a>
Source§impl DivAssign<&Relaxed> for Relaxed
impl DivAssign<&Relaxed> for Relaxed
Source§fn div_assign(&mut self, rhs: &Relaxed)
fn div_assign(&mut self, rhs: &Relaxed)
/=
operation. Read moreSource§impl DivAssign for Relaxed
impl DivAssign for Relaxed
Source§fn div_assign(&mut self, rhs: Relaxed)
fn div_assign(&mut self, rhs: Relaxed)
/=
operation. Read moreSource§impl<'l, 'r> DivRemEuclid<&'r Relaxed> for &'l Relaxed
impl<'l, 'r> DivRemEuclid<&'r Relaxed> for &'l Relaxed
Source§impl<'r> DivRemEuclid<&'r Relaxed> for Relaxed
impl<'r> DivRemEuclid<&'r Relaxed> for Relaxed
Source§impl<'l> DivRemEuclid<Relaxed> for &'l Relaxed
impl<'l> DivRemEuclid<Relaxed> for &'l Relaxed
Source§impl DivRemEuclid for Relaxed
impl DivRemEuclid for Relaxed
Source§impl EstimatedLog2 for Relaxed
impl EstimatedLog2 for Relaxed
Source§impl Euclid for Relaxed
impl Euclid for Relaxed
Source§fn div_euclid(&self, v: &Self) -> Self
fn div_euclid(&self, v: &Self) -> Self
rem_euclid
. Read moreSource§fn rem_euclid(&self, v: &Self) -> Self
fn rem_euclid(&self, v: &Self) -> Self
self (mod v)
. Read moreSource§fn div_rem_euclid(&self, v: &Self) -> (Self, Self)
fn div_rem_euclid(&self, v: &Self) -> (Self, Self)
Source§impl FromPrimitive for Relaxed
impl FromPrimitive for Relaxed
Source§fn from_i8(n: i8) -> Option<Self>
fn from_i8(n: i8) -> Option<Self>
i8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_i16(n: i16) -> Option<Self>
fn from_i16(n: i16) -> Option<Self>
i16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_i32(n: i32) -> Option<Self>
fn from_i32(n: i32) -> Option<Self>
i32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_i64(n: i64) -> Option<Self>
fn from_i64(n: i64) -> Option<Self>
i64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_i128(n: i128) -> Option<Self>
fn from_i128(n: i128) -> Option<Self>
i128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moreSource§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
isize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_u8(n: u8) -> Option<Self>
fn from_u8(n: u8) -> Option<Self>
u8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_u16(n: u16) -> Option<Self>
fn from_u16(n: u16) -> Option<Self>
u16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_u32(n: u32) -> Option<Self>
fn from_u32(n: u32) -> Option<Self>
u32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_u64(n: u64) -> Option<Self>
fn from_u64(n: u64) -> Option<Self>
u64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_u128(n: u128) -> Option<Self>
fn from_u128(n: u128) -> Option<Self>
u128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moreSource§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
usize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§impl MulAssign<&Relaxed> for Relaxed
impl MulAssign<&Relaxed> for Relaxed
Source§fn mul_assign(&mut self, rhs: &Relaxed)
fn mul_assign(&mut self, rhs: &Relaxed)
*=
operation. Read moreSource§impl MulAssign for Relaxed
impl MulAssign for Relaxed
Source§fn mul_assign(&mut self, rhs: Relaxed)
fn mul_assign(&mut self, rhs: Relaxed)
*=
operation. Read moreSource§impl Num for Relaxed
impl Num for Relaxed
type FromStrRadixErr = ParseError
Source§fn from_str_radix(src: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(src: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
2..=36
). Read moreSource§impl<R: Round, const B: Word> NumOrd<FBig<R, B>> for Relaxed
impl<R: Round, const B: Word> NumOrd<FBig<R, B>> for Relaxed
Source§impl NumOrd<IBig> for Relaxed
impl NumOrd<IBig> for Relaxed
Source§impl NumOrd<RBig> for Relaxed
impl NumOrd<RBig> for Relaxed
Source§impl<R: Round, const B: Word> NumOrd<Relaxed> for FBig<R, B>
impl<R: Round, const B: Word> NumOrd<Relaxed> for FBig<R, B>
Source§impl NumOrd<Relaxed> for IBig
impl NumOrd<Relaxed> for IBig
Source§impl NumOrd<Relaxed> for RBig
impl NumOrd<Relaxed> for RBig
Source§impl NumOrd<Relaxed> for UBig
impl NumOrd<Relaxed> for UBig
Source§impl NumOrd<Relaxed> for f32
impl NumOrd<Relaxed> for f32
Source§impl NumOrd<Relaxed> for f64
impl NumOrd<Relaxed> for f64
Source§impl NumOrd<Relaxed> for i128
impl NumOrd<Relaxed> for i128
Source§impl NumOrd<Relaxed> for i16
impl NumOrd<Relaxed> for i16
Source§impl NumOrd<Relaxed> for i32
impl NumOrd<Relaxed> for i32
Source§impl NumOrd<Relaxed> for i64
impl NumOrd<Relaxed> for i64
Source§impl NumOrd<Relaxed> for i8
impl NumOrd<Relaxed> for i8
Source§impl NumOrd<Relaxed> for isize
impl NumOrd<Relaxed> for isize
Source§impl NumOrd<Relaxed> for u128
impl NumOrd<Relaxed> for u128
Source§impl NumOrd<Relaxed> for u16
impl NumOrd<Relaxed> for u16
Source§impl NumOrd<Relaxed> for u32
impl NumOrd<Relaxed> for u32
Source§impl NumOrd<Relaxed> for u64
impl NumOrd<Relaxed> for u64
Source§impl NumOrd<Relaxed> for u8
impl NumOrd<Relaxed> for u8
Source§impl NumOrd<Relaxed> for usize
impl NumOrd<Relaxed> for usize
Source§impl NumOrd<UBig> for Relaxed
impl NumOrd<UBig> for Relaxed
Source§impl NumOrd<f32> for Relaxed
impl NumOrd<f32> for Relaxed
Source§impl NumOrd<f64> for Relaxed
impl NumOrd<f64> for Relaxed
Source§impl NumOrd<i128> for Relaxed
impl NumOrd<i128> for Relaxed
Source§impl NumOrd<i16> for Relaxed
impl NumOrd<i16> for Relaxed
Source§impl NumOrd<i32> for Relaxed
impl NumOrd<i32> for Relaxed
Source§impl NumOrd<i64> for Relaxed
impl NumOrd<i64> for Relaxed
Source§impl NumOrd<i8> for Relaxed
impl NumOrd<i8> for Relaxed
Source§impl NumOrd<isize> for Relaxed
impl NumOrd<isize> for Relaxed
Source§impl NumOrd<u128> for Relaxed
impl NumOrd<u128> for Relaxed
Source§impl NumOrd<u16> for Relaxed
impl NumOrd<u16> for Relaxed
Source§impl NumOrd<u32> for Relaxed
impl NumOrd<u32> for Relaxed
Source§impl NumOrd<u64> for Relaxed
impl NumOrd<u64> for Relaxed
Source§impl NumOrd<u8> for Relaxed
impl NumOrd<u8> for Relaxed
Source§impl NumOrd<usize> for Relaxed
impl NumOrd<usize> for Relaxed
Source§impl Ord for Relaxed
impl Ord for Relaxed
Source§impl PartialOrd for Relaxed
impl PartialOrd for Relaxed
Source§impl RemAssign<&Relaxed> for Relaxed
impl RemAssign<&Relaxed> for Relaxed
Source§fn rem_assign(&mut self, rhs: &Relaxed)
fn rem_assign(&mut self, rhs: &Relaxed)
%=
operation. Read moreSource§impl RemAssign for Relaxed
impl RemAssign for Relaxed
Source§fn rem_assign(&mut self, rhs: Relaxed)
fn rem_assign(&mut self, rhs: Relaxed)
%=
operation. Read moreSource§impl Signed for Relaxed
impl Signed for Relaxed
Source§fn is_positive(&self) -> bool
fn is_positive(&self) -> bool
Source§fn is_negative(&self) -> bool
fn is_negative(&self) -> bool
Source§impl SubAssign<&Relaxed> for Relaxed
impl SubAssign<&Relaxed> for Relaxed
Source§fn sub_assign(&mut self, rhs: &Relaxed)
fn sub_assign(&mut self, rhs: &Relaxed)
-=
operation. Read moreSource§impl SubAssign for Relaxed
impl SubAssign for Relaxed
Source§fn sub_assign(&mut self, rhs: Relaxed)
fn sub_assign(&mut self, rhs: Relaxed)
-=
operation. Read moreSource§impl ToPrimitive for Relaxed
impl ToPrimitive for Relaxed
Source§fn to_i8(&self) -> Option<i8>
fn to_i8(&self) -> Option<i8>
self
to an i8
. If the value cannot be
represented by an i8
, then None
is returned.Source§fn to_i16(&self) -> Option<i16>
fn to_i16(&self) -> Option<i16>
self
to an i16
. If the value cannot be
represented by an i16
, then None
is returned.Source§fn to_i32(&self) -> Option<i32>
fn to_i32(&self) -> Option<i32>
self
to an i32
. If the value cannot be
represented by an i32
, then None
is returned.Source§fn to_i64(&self) -> Option<i64>
fn to_i64(&self) -> Option<i64>
self
to an i64
. If the value cannot be
represented by an i64
, then None
is returned.Source§fn to_i128(&self) -> Option<i128>
fn to_i128(&self) -> Option<i128>
self
to an i128
. If the value cannot be
represented by an i128
(i64
under the default implementation), then
None
is returned. Read moreSource§fn to_isize(&self) -> Option<isize>
fn to_isize(&self) -> Option<isize>
self
to an isize
. If the value cannot be
represented by an isize
, then None
is returned.Source§fn to_u8(&self) -> Option<u8>
fn to_u8(&self) -> Option<u8>
self
to a u8
. If the value cannot be
represented by a u8
, then None
is returned.Source§fn to_u16(&self) -> Option<u16>
fn to_u16(&self) -> Option<u16>
self
to a u16
. If the value cannot be
represented by a u16
, then None
is returned.Source§fn to_u32(&self) -> Option<u32>
fn to_u32(&self) -> Option<u32>
self
to a u32
. If the value cannot be
represented by a u32
, then None
is returned.Source§fn to_u64(&self) -> Option<u64>
fn to_u64(&self) -> Option<u64>
self
to a u64
. If the value cannot be
represented by a u64
, then None
is returned.Source§fn to_u128(&self) -> Option<u128>
fn to_u128(&self) -> Option<u128>
self
to a u128
. If the value cannot be
represented by a u128
(u64
under the default implementation), then
None
is returned. Read moreSource§fn to_usize(&self) -> Option<usize>
fn to_usize(&self) -> Option<usize>
self
to a usize
. If the value cannot be
represented by a usize
, then None
is returned.