pub struct r64(/* private fields */);Expand description
The 64-bit floating bar type.
Implementations§
Source§impl r64
impl r64
Sourcepub const unsafe fn new_unchecked(numer: i64, denom: u64) -> r64
pub const unsafe fn new_unchecked(numer: i64, denom: u64) -> r64
Creates a rational number without checking the values.
§Safety
The values must fit in the fraction field.
Sourcepub fn new(numer: i64, denom: u64) -> Option<r64>
pub fn new(numer: i64, denom: u64) -> Option<r64>
Creates a rational number if the given values both fit in the fraction field.
Sourcepub fn sqrt(self) -> r64
pub fn sqrt(self) -> r64
Calculates the approximate square root of the value.
Warning: This method can give a number that overflows easily, so use it with caution, and discard it as soon as you’re done with it.
Sourcepub fn cbrt(self) -> r64
pub fn cbrt(self) -> r64
Calculates the approximate cube root of the value.
Warning: This method can give a number that overflows easily, so use it with caution, and discard it as soon as you’re done with it.
Sourcepub fn checked_add(self, rhs: r64) -> Option<r64>
pub fn checked_add(self, rhs: r64) -> Option<r64>
Checked rational addition. Computes self + rhs, returning None if
overflow occurred.
Sourcepub fn checked_mul(self, rhs: r64) -> Option<r64>
pub fn checked_mul(self, rhs: r64) -> Option<r64>
Checked rational multiplication. Computes self * rhs, returning None
if overflow occurred.
Source§impl r64
impl r64
Sourcepub const MIN_POSITIVE: r64
pub const MIN_POSITIVE: r64
The smallest positive value that can be represented by this rational type.
Sourcepub fn is_positive(self) -> bool
pub fn is_positive(self) -> bool
Returns true if self is positive and false if the number is zero,
negative, or NAN.
Sourcepub fn is_negative(self) -> bool
pub fn is_negative(self) -> bool
Returns true if self is negative and false if the number is zero,
positive, or NAN.
Sourcepub fn round(self) -> r64
pub fn round(self) -> r64
Returns the nearest integer to a number. Round half-way cases away from zero.
Sourcepub fn signum(self) -> r64
pub fn signum(self) -> r64
Returns a number that represents the sign of self.
1if the number is positive-1if the number is negative0if the number is0NANif the number isNAN.
Sourcepub fn normalize(self) -> r64
pub fn normalize(self) -> r64
Cancels out common factors between the numerator and the denominator.
Sourcepub fn pow(self, exp: i32) -> r64
pub fn pow(self, exp: i32) -> r64
Checked exponentiation. Computes self.pow(exp), returning None if
overflow occurred.
Sourcepub fn max(self, other: r64) -> r64
pub fn max(self, other: r64) -> r64
Returns the maximum of the two numbers.
If one of the arguments is NaN, then the other argument is returned.
Sourcepub fn min(self, other: r64) -> r64
pub fn min(self, other: r64) -> r64
Returns the minimum of the two numbers.
If one of the arguments is NaN, then the other argument is returned.
Sourcepub fn checked_neg(self) -> Option<r64>
pub fn checked_neg(self) -> Option<r64>
Checked rational negation. Computes -self, returning None if the
numerator would overflow.
Sourcepub fn checked_abs(self) -> Option<r64>
pub fn checked_abs(self) -> Option<r64>
Checked absolute value. Computes self.abs(), returning None if the
numerator would overflow.
Sourcepub fn checked_recip(self) -> Option<r64>
pub fn checked_recip(self) -> Option<r64>
Checked reciprocal. Computes 1/self, returning None if the
numerator is zero.
Sourcepub fn checked_pow(self, exp: i32) -> Option<r64>
pub fn checked_pow(self, exp: i32) -> Option<r64>
Checked exponentiation. Computes self.pow(exp), returning None if
overflow occurred.
Sourcepub fn checked_sub(self, rhs: r64) -> Option<r64>
pub fn checked_sub(self, rhs: r64) -> Option<r64>
Checked subtraction. Computes self - rhs, returning None if
overflow occurred.
Sourcepub fn checked_div(self, rhs: r64) -> Option<r64>
pub fn checked_div(self, rhs: r64) -> Option<r64>
Checked rational division. Computes self / rhs, returning None if
rhs == 0 or the division results in overflow.
Sourcepub fn checked_rem(self, rhs: r64) -> Option<r64>
pub fn checked_rem(self, rhs: r64) -> Option<r64>
Checked rational remainder. Computes self % rhs, returning None if
rhs == 0 or the division results in overflow.
Trait Implementations§
Source§impl AddAssign for r64
impl AddAssign for r64
Source§fn add_assign(&mut self, other: r64)
fn add_assign(&mut self, other: r64)
+= operation. Read moreSource§impl DivAssign for r64
impl DivAssign for r64
Source§fn div_assign(&mut self, other: r64)
fn div_assign(&mut self, other: r64)
/= operation. Read moreSource§impl FromStr for r64
impl FromStr for r64
Source§fn from_str(src: &str) -> Result<Self, Self::Err>
fn from_str(src: &str) -> Result<Self, Self::Err>
Converts a string in base 10 to a rational.
This function accepts strings such as
- ‘157/50’
- ‘-157/50’
- ‘25’, or equivalently, ‘25/1’
- ‘NaN’
Leading and trailing whitespace represent an error.
§Return value
Err(ParseRatioError) if the string did not contain a valid rational
number. Otherwise, Ok(n) where n is the floating-bar number
represented by src.
Source§type Err = ParseRatioErr
type Err = ParseRatioErr
Source§impl MulAssign for r64
impl MulAssign for r64
Source§fn mul_assign(&mut self, other: r64)
fn mul_assign(&mut self, other: r64)
*= operation. Read moreSource§impl PartialOrd for r64
impl PartialOrd for r64
Source§impl RemAssign for r64
impl RemAssign for r64
Source§fn rem_assign(&mut self, other: r64)
fn rem_assign(&mut self, other: r64)
%= operation. Read moreSource§impl SubAssign for r64
impl SubAssign for r64
Source§fn sub_assign(&mut self, other: r64)
fn sub_assign(&mut self, other: r64)
-= operation. Read more