r64

Struct r64 

Source
pub struct r64(/* private fields */);
Expand description

The 64-bit floating bar type.

Implementations§

Source§

impl r64

Source

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.

Source

pub fn new(numer: i64, denom: u64) -> Option<r64>

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

Source

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.

Source

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.

Source

pub fn checked_add(self, rhs: r64) -> Option<r64>

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

Source

pub fn checked_mul(self, rhs: r64) -> Option<r64>

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

Source

pub fn to_i64(self) -> Option<i64>

Checked conversion to i64.

Returns i64 value if denominator is 1. Otherwise, returns None.

Source§

impl r64

Source

pub const MAX: r64

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

Source

pub const MIN: r64

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

Source

pub const MIN_POSITIVE: r64

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

Source

pub const NAN: r64

Not a Number (NaN).

Source

pub fn is_nan(self) -> bool

Returns true if this value is NAN and false otherwise.

Source

pub fn is_positive(self) -> bool

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

Source

pub fn is_negative(self) -> bool

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

Source

pub fn trunc(self) -> r64

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

Source

pub fn fract(self) -> r64

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

Source

pub fn floor(self) -> r64

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

Source

pub fn ceil(self) -> r64

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

Source

pub fn round(self) -> r64

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

Source

pub fn abs(self) -> r64

Computes the absolute value of self.

Source

pub fn signum(self) -> r64

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.
Source

pub fn recip(self) -> r64

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

§Panics

Panics when the numerator is zero.

Source

pub fn normalize(self) -> r64

Cancels out common factors between the numerator and the denominator.

Source

pub fn pow(self, exp: i32) -> r64

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

Source

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.

Source

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.

Source

pub fn checked_neg(self) -> Option<r64>

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

Source

pub fn checked_abs(self) -> Option<r64>

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

Source

pub fn checked_recip(self) -> Option<r64>

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

Source

pub fn checked_pow(self, exp: i32) -> Option<r64>

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

Source

pub fn checked_sub(self, rhs: r64) -> Option<r64>

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

Source

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.

Source

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.

Source

pub fn to_bits(self) -> u64

Raw transmutation to u64.

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

Source

pub fn from_bits(bits: u64) -> r64

Raw transmutation from u64.

Trait Implementations§

Source§

impl Add for r64

Source§

type Output = r64

The resulting type after applying the + operator.
Source§

fn add(self, other: r64) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign for r64

Source§

fn add_assign(&mut self, other: r64)

Performs the += operation. Read more
Source§

impl Clone for r64

Source§

fn clone(&self) -> r64

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for r64

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for r64

Source§

fn default() -> r64

Returns the “default value” for a type. Read more
Source§

impl Display for r64

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div for r64

Source§

type Output = r64

The resulting type after applying the / operator.
Source§

fn div(self, other: r64) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign for r64

Source§

fn div_assign(&mut self, other: r64)

Performs the /= operation. Read more
Source§

impl From<f32> for r64

Source§

fn from(f: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for r64

Source§

impl From<i16> for r64

Source§

fn from(v: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for r64

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for r64

Source§

fn from(v: i8) -> Self

Converts to this type from the input type.
Source§

impl From<r32> for r64

Source§

fn from(v: r32) -> Self

Converts to this type from the input type.
Source§

impl From<r64> for f32

Source§

fn from(r: r64) -> f32

Converts to this type from the input type.
Source§

impl From<r64> for f64

Source§

fn from(r: r64) -> f64

Converts to this type from the input type.
Source§

impl From<u16> for r64

Source§

fn from(v: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for r64

Source§

fn from(v: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for r64

Source§

fn from(v: u8) -> Self

Converts to this type from the input type.
Source§

impl FromStr for r64

Source§

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

The associated error which can be returned from parsing.
Source§

impl Mul for r64

Source§

type Output = r64

The resulting type after applying the * operator.
Source§

fn mul(self, other: r64) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign for r64

Source§

fn mul_assign(&mut self, other: r64)

Performs the *= operation. Read more
Source§

impl Neg for r64

Source§

type Output = r64

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for r64

Source§

fn eq(&self, other: &r64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for r64

Source§

fn partial_cmp(&self, other: &r64) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Rem for r64

Source§

type Output = r64

The resulting type after applying the % operator.
Source§

fn rem(self, other: r64) -> Self::Output

Performs the % operation. Read more
Source§

impl RemAssign for r64

Source§

fn rem_assign(&mut self, other: r64)

Performs the %= operation. Read more
Source§

impl Sub for r64

Source§

type Output = r64

The resulting type after applying the - operator.
Source§

fn sub(self, other: r64) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign for r64

Source§

fn sub_assign(&mut self, other: r64)

Performs the -= operation. Read more
Source§

impl Copy for r64

Source§

impl Eq for r64

Auto Trait Implementations§

§

impl Freeze for r64

§

impl RefUnwindSafe for r64

§

impl Send for r64

§

impl Sync for r64

§

impl Unpin for r64

§

impl UnwindSafe for r64

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.