Struct floating_bar::r32[][src]

pub struct r32(_);

The 32-bit floating bar type.

Implementations

impl r32[src]

pub const unsafe fn new_unchecked(numer: i32, denom: u32) -> r32[src]

Creates a rational number without checking the values.

Safety

The values must fit in the fraction field.

pub fn new(numer: i32, denom: u32) -> Option<r32>[src]

Creates a rational number if the given values both fit in the fraction field.

pub fn sqrt(self) -> r32[src]

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.

pub fn cbrt(self) -> r32[src]

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.

pub fn checked_add(self, rhs: r32) -> Option<r32>[src]

Checked addition. Computes self + rhs, returning None if overflow occurred.

pub fn checked_mul(self, rhs: r32) -> Option<r32>[src]

Checked multiplication. Computes self * rhs, returning None if overflow occurred.

If one argument is NaN and the other is zero, this returns zero.

pub fn to_i32(self) -> Option<i32>[src]

Checked conversion to i32.

Returns the numeric value as an i32 if its irreducible form has a denominator of 1. Otherwise, returns None.

impl r32[src]

pub const MAX: r32[src]

The highest value that can be represented by this rational type.

pub const MIN: r32[src]

The lowest value that can be represented by this rational type.

pub const MIN_POSITIVE: r32[src]

The smallest positive value that can be represented by this rational type.

pub const NAN: r32[src]

Not a Number (NaN).

pub fn is_nan(self) -> bool[src]

Returns true if this value is NAN and false otherwise.

pub fn is_positive(self) -> bool[src]

Returns true if self is positive and false if the number is zero, negative, or NAN.

pub fn is_negative(self) -> bool[src]

Returns true if self is negative and false if the number is zero, positive, or NAN.

pub fn trunc(self) -> r32[src]

Returns the integer part of a number, or NaN if self is NaN.

pub fn fract(self) -> r32[src]

Returns the fractional part of a number, or NaN if self is NaN.

pub fn floor(self) -> r32[src]

Returns the largest integer less than or equal to a number.

pub fn ceil(self) -> r32[src]

Returns the smallest integer greater than or equal to a number.

pub fn round(self) -> r32[src]

Returns the nearest integer to a number. Round half-way cases away from zero.

pub fn abs(self) -> r32[src]

Computes the absolute value of self.

pub fn signum(self) -> r32[src]

Returns a number that represents the sign of self.

  • 1 if the number is positive
  • -1 if the number is negative
  • 0 if the number is 0
  • NAN if the number is NAN.

pub fn recip(self) -> r32[src]

Takes the reciprocal (inverse) of a number, 1/x.

Panics

Panics when the numerator is zero.

pub fn normalize(self) -> r32[src]

Cancels out common factors between the numerator and the denominator.

pub fn pow(self, exp: i32) -> r32[src]

Checked exponentiation. Computes self.pow(exp), returning None if overflow occurred.

pub fn max(self, other: r32) -> r32[src]

Returns the maximum of the two numbers.

If one of the arguments is NaN, then the other argument is returned.

pub fn min(self, other: r32) -> r32[src]

Returns the minimum of the two numbers.

If one of the arguments is NaN, then the other argument is returned.

pub fn checked_neg(self) -> Option<r32>[src]

Checked rational negation. Computes -self, returning None if the numerator would overflow.

pub fn checked_abs(self) -> Option<r32>[src]

Checked absolute value. Computes self.abs(), returning None if the numerator would overflow.

pub fn checked_recip(self) -> Option<r32>[src]

Checked reciprocal. Computes 1/self, returning None if the numerator is zero.

pub fn checked_pow(self, exp: i32) -> Option<r32>[src]

Checked exponentiation. Computes self.pow(exp), returning None if overflow occurred.

pub fn checked_sub(self, rhs: r32) -> Option<r32>[src]

Checked subtraction. Computes self - rhs, returning None if overflow occurred.

pub fn checked_div(self, rhs: r32) -> Option<r32>[src]

Checked rational division. Computes self / rhs, returning None if rhs == 0 or the division results in overflow.

pub fn checked_rem(self, rhs: r32) -> Option<r32>[src]

Checked rational remainder. Computes self % rhs, returning None if rhs == 0 or the division results in overflow.

pub fn to_bits(self) -> u32[src]

Raw transmutation to u64.

Useful if you need access to the payload bits of a NaN value.

pub fn from_bits(bits: u32) -> r32[src]

Raw transmutation from u64.

Trait Implementations

impl Add<r32> for r32[src]

type Output = r32

The resulting type after applying the + operator.

impl AddAssign<r32> for r32[src]

impl Clone for r32[src]

impl Copy for r32[src]

impl Debug for r32[src]

impl Default for r32[src]

impl Display for r32[src]

impl Div<r32> for r32[src]

type Output = r32

The resulting type after applying the / operator.

impl DivAssign<r32> for r32[src]

impl Eq for r32[src]

impl From<f32> for r32[src]

impl From<i16> for r32[src]

impl From<i8> for r32[src]

impl From<r32> for r64[src]

impl From<u16> for r32[src]

impl From<u8> for r32[src]

impl FromStr for r32[src]

type Err = ParseRatioErr

The associated error which can be returned from parsing.

fn from_str(src: &str) -> Result<Self, Self::Err>[src]

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.

impl Mul<r32> for r32[src]

type Output = r32

The resulting type after applying the * operator.

impl MulAssign<r32> for r32[src]

impl Neg for r32[src]

type Output = r32

The resulting type after applying the - operator.

impl PartialEq<r32> for r32[src]

impl PartialOrd<r32> for r32[src]

impl Rem<r32> for r32[src]

type Output = r32

The resulting type after applying the % operator.

impl RemAssign<r32> for r32[src]

impl StructuralEq for r32[src]

impl Sub<r32> for r32[src]

type Output = r32

The resulting type after applying the - operator.

impl SubAssign<r32> for r32[src]

Auto Trait Implementations

impl RefUnwindSafe for r32

impl Send for r32

impl Sync for r32

impl Unpin for r32

impl UnwindSafe for r32

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.