pub struct r32(/* private fields */);Expand description
The 32-bit floating bar type.
Implementations§
Source§impl r32
impl r32
Sourcepub const unsafe fn new_unchecked(numer: i32, denom: u32) -> r32
pub const unsafe fn new_unchecked(numer: i32, denom: u32) -> r32
Creates a rational number without checking the values.
§Safety
The values must fit in the fraction field.
Sourcepub fn new(numer: i32, denom: u32) -> Option<r32>
pub fn new(numer: i32, denom: u32) -> Option<r32>
Creates a rational number if the given values both fit in the fraction field.
Sourcepub fn sqrt(self) -> r32
pub fn sqrt(self) -> r32
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) -> r32
pub fn cbrt(self) -> r32
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: r32) -> Option<r32>
pub fn checked_add(self, rhs: r32) -> Option<r32>
Checked addition. Computes self + rhs, returning None if overflow
occurred.
Sourcepub fn checked_mul(self, rhs: r32) -> Option<r32>
pub fn checked_mul(self, rhs: r32) -> Option<r32>
Checked multiplication. Computes self * rhs, returning None
if overflow occurred.
If one argument is NaN and the other is zero, this returns zero.
Source§impl r32
impl r32
Sourcepub const MIN_POSITIVE: r32
pub const MIN_POSITIVE: r32
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) -> r32
pub fn round(self) -> r32
Returns the nearest integer to a number. Round half-way cases away from zero.
Sourcepub fn signum(self) -> r32
pub fn signum(self) -> r32
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) -> r32
pub fn normalize(self) -> r32
Cancels out common factors between the numerator and the denominator.
Sourcepub fn pow(self, exp: i32) -> r32
pub fn pow(self, exp: i32) -> r32
Checked exponentiation. Computes self.pow(exp), returning None if
overflow occurred.
Sourcepub fn max(self, other: r32) -> r32
pub fn max(self, other: r32) -> r32
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: r32) -> r32
pub fn min(self, other: r32) -> r32
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<r32>
pub fn checked_neg(self) -> Option<r32>
Checked rational negation. Computes -self, returning None if the
numerator would overflow.
Sourcepub fn checked_abs(self) -> Option<r32>
pub fn checked_abs(self) -> Option<r32>
Checked absolute value. Computes self.abs(), returning None if the
numerator would overflow.
Sourcepub fn checked_recip(self) -> Option<r32>
pub fn checked_recip(self) -> Option<r32>
Checked reciprocal. Computes 1/self, returning None if the
numerator is zero.
Sourcepub fn checked_pow(self, exp: i32) -> Option<r32>
pub fn checked_pow(self, exp: i32) -> Option<r32>
Checked exponentiation. Computes self.pow(exp), returning None if
overflow occurred.
Sourcepub fn checked_sub(self, rhs: r32) -> Option<r32>
pub fn checked_sub(self, rhs: r32) -> Option<r32>
Checked subtraction. Computes self - rhs, returning None if
overflow occurred.
Sourcepub fn checked_div(self, rhs: r32) -> Option<r32>
pub fn checked_div(self, rhs: r32) -> Option<r32>
Checked rational division. Computes self / rhs, returning None if
rhs == 0 or the division results in overflow.
Sourcepub fn checked_rem(self, rhs: r32) -> Option<r32>
pub fn checked_rem(self, rhs: r32) -> Option<r32>
Checked rational remainder. Computes self % rhs, returning None if
rhs == 0 or the division results in overflow.
Trait Implementations§
Source§impl AddAssign for r32
impl AddAssign for r32
Source§fn add_assign(&mut self, other: r32)
fn add_assign(&mut self, other: r32)
+= operation. Read moreSource§impl DivAssign for r32
impl DivAssign for r32
Source§fn div_assign(&mut self, other: r32)
fn div_assign(&mut self, other: r32)
/= operation. Read moreSource§impl FromStr for r32
impl FromStr for r32
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 r32
impl MulAssign for r32
Source§fn mul_assign(&mut self, other: r32)
fn mul_assign(&mut self, other: r32)
*= operation. Read moreSource§impl PartialOrd for r32
impl PartialOrd for r32
Source§impl RemAssign for r32
impl RemAssign for r32
Source§fn rem_assign(&mut self, other: r32)
fn rem_assign(&mut self, other: r32)
%= operation. Read moreSource§impl SubAssign for r32
impl SubAssign for r32
Source§fn sub_assign(&mut self, other: r32)
fn sub_assign(&mut self, other: r32)
-= operation. Read more