Struct extended_rational::Rational
[−]
[src]
pub struct Rational { /* fields omitted */ }
A type representing a signed projectively-extended rational number
Examples
use extended_rational::Rational; let a = Rational::new(3, 17); let b = Rational::new(-4, 7); assert_eq!(a+b, Rational::new(-47, 119));
Use the ratio! macro for more convenient use.
let a = ratio!(3, 17); let b = ratio!(-4, 7);
Or for easy conversions from primitive types.
let a = ratio!(-77.332); let b = ratio!(2u8);
Methods
impl Rational
[src]
fn new(numerator: i64, denominator: i64) -> Rational
[src]
Create a new signed rational with the given numerator and denominator.
fn new_raw(unsigned: URational, negative: bool) -> Rational
[src]
Create a new signed rational with the given unsigned rational and sign.
fn numerator(self) -> u64
[src]
Returns the underlying numerator of this rational.
fn numerator_mut(&mut self) -> &mut u64
[src]
Returns the underlying numerator of this rational mutably.
fn denominator(self) -> u64
[src]
Returns the underlying denominator of this rational.
fn denominator_mut(&mut self) -> &mut u64
[src]
Returns the underlying denominator of this rational mutably.
fn sign(self) -> bool
[src]
Returns the underlying sign of this rational.
fn sign_mut(&mut self) -> &mut bool
[src]
Returns the underlying sign of this rational mutably.
fn unsigned(self) -> URational
[src]
Returns the underlying unsigned rational of this rational.
fn unsigned_mut(&mut self) -> &mut URational
[src]
Returns the underlying unsigned rational of this rational mutably.
fn try_unsigned(self) -> URational
[src]
Returns the underlying unsigned rational of this rational, panicking if sign is negative.
Does not panic in optimized builds.
fn min_value() -> Rational
[src]
Returns the smallest value a signed rational can store.
fn min_pos_value() -> Rational
[src]
Returns the smallest positive value a signed rational can store.
fn max_neg_value() -> Rational
[src]
Returns the largest negative value a signed rational can store.
fn max_value() -> Rational
[src]
Returns the largest value a signed rational can store.
fn nan() -> Rational
[src]
Returns a signed rational representing NaN
.
fn zero() -> Rational
[src]
Returns a signed rational representing 0
.
fn infinity() -> Rational
[src]
Returns a signed rational representing ∞
.
fn one() -> Rational
[src]
Returns a signed rational representing 1
.
fn negative_one() -> Rational
[src]
Returns a signed rational representing -1
.
fn is_nan(self) -> bool
[src]
Returns true
if this rational is NaN
and false
otherwise.
fn is_zero(self) -> bool
[src]
Returns true
if this rational is 0
and false
otherwise.
fn is_infinity(self) -> bool
[src]
Returns true
if this rational is ∞
and false
otherwise.
fn is_signed(self) -> bool
[src]
Returns true
if this rational is a signed number (not NaN
, 0
, or ∞
) and false
otherwise.
fn is_negative(self) -> bool
[src]
Returns true
if this rational is a negative number and false
otherwise.
fn reciprocal(self) -> Rational
[src]
Returns the reciprocal of this rational.
fn negative_reciprocal(self) -> Rational
[src]
Returns the negative reciprocal of this rational.
fn complexity(self) -> u64
[src]
Returns the complexity of this rational (max of absolute values of numerator and denominator).
fn is_positive(self) -> bool
[src]
Returns true
if this rational is a positive number and false
otherwise.
fn floor(self) -> Rational
[src]
Returns this rational with no fractional component by rounding towards zero.
fn round(self) -> Rational
[src]
Returns this rational with no fractional component by rounding.
fn ceil(self) -> Rational
[src]
Returns this rational with no fractional component by rounding away from zero.
fn abs(self) -> Rational
[src]
Returns this rational without a negative sign.
fn add_exact(self, other: Rational) -> Option<Rational>
[src]
Computes self + other
, returning None
if rounding occurred.
fn sub_exact(self, other: Rational) -> Option<Rational>
[src]
Computes self - other
, returning None
if rounding occurred.
fn mul_exact(self, other: Rational) -> Option<Rational>
[src]
Computes self * other
, returning None
if rounding occurred.
fn div_exact(self, other: Rational) -> Option<Rational>
[src]
Computes self / other
, returning None
if rounding occurred.
fn rem_exact(self, other: Rational) -> Option<Rational>
[src]
Computes self % other
, returning None
if rounding occurred.
Trait Implementations
impl Copy for Rational
[src]
impl Clone for Rational
[src]
fn clone(&self) -> Rational
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Default for Rational
[src]
impl PartialEq for Rational
[src]
fn eq(&self, other: &Rational) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialOrd for Rational
[src]
fn partial_cmp(&self, other: &Rational) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Display for Rational
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the rational.
Style
NaN
,∞
, and whole numbers are written directly- Ratios with complexities less than 100 are written as fractions (
n/d
) - All other numbers are written as decimals
impl Debug for Rational
[src]
impl AddAssign for Rational
[src]
fn add_assign(&mut self, other: Rational)
[src]
Performs the +=
operation.
impl Add for Rational
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: Rational) -> Rational
[src]
Performs the +
operation.
impl SubAssign for Rational
[src]
fn sub_assign(&mut self, other: Rational)
[src]
Performs the -=
operation.
impl Sub for Rational
[src]
type Output = Rational
The resulting type after applying the -
operator.
fn sub(self, other: Rational) -> Rational
[src]
Performs the -
operation.
impl MulAssign for Rational
[src]
fn mul_assign(&mut self, other: Rational)
[src]
Performs the *=
operation.
impl Mul for Rational
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: Rational) -> Rational
[src]
Performs the *
operation.
impl DivAssign for Rational
[src]
fn div_assign(&mut self, other: Rational)
[src]
Performs the /=
operation.
impl Div for Rational
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: Rational) -> Rational
[src]
Performs the /
operation.
impl RemAssign for Rational
[src]
fn rem_assign(&mut self, other: Rational)
[src]
Performs the %=
operation.
impl Rem for Rational
[src]
type Output = Rational
The resulting type after applying the %
operator.
fn rem(self, other: Rational) -> Rational
[src]
Performs the %
operation.
impl Neg for Rational
[src]
type Output = Rational
The resulting type after applying the -
operator.
fn neg(self) -> Rational
[src]
Performs the unary -
operation.
impl From<URational> for Rational
[src]
impl From<(URational, bool)> for Rational
[src]
fn from(tuple: (URational, bool)) -> Rational
[src]
Create a new signed rational from an unsigned rational and a sign.
impl From<f64> for Rational
[src]
fn from(f: f64) -> Rational
[src]
Attempts to approximate the given floating-point number with a signed rational.
Rounding
- If the exponent is too large,
∞
will be returned - If the exponent is too small,
0
will be returned
impl From<f32> for Rational
[src]
fn from(f: f32) -> Rational
[src]
Attempts to approximate the given floating-point number with a signed rational.
Rounding
- If the exponent is too large,
∞
will be returned - If the exponent is too small,
0
will be returned
impl From<u64> for Rational
[src]
impl From<(u64, u64)> for Rational
[src]
fn from(tuple: (u64, u64)) -> Rational
[src]
Create a new signed rational with the given numerator and denominator tuple.
impl From<[u64; 2]> for Rational
[src]
fn from(array: [u64; 2]) -> Rational
[src]
Create a new signed rational with the given numerator and denominator array.
impl From<u32> for Rational
[src]
impl From<(u32, u32)> for Rational
[src]
fn from(tuple: (u32, u32)) -> Rational
[src]
Create a new signed rational with the given numerator and denominator tuple.
impl From<[u32; 2]> for Rational
[src]
fn from(array: [u32; 2]) -> Rational
[src]
Create a new signed rational with the given numerator and denominator array.
impl From<u16> for Rational
[src]
impl From<(u16, u16)> for Rational
[src]
fn from(tuple: (u16, u16)) -> Rational
[src]
Create a new signed rational with the given numerator and denominator tuple.
impl From<[u16; 2]> for Rational
[src]
fn from(array: [u16; 2]) -> Rational
[src]
Create a new signed rational with the given numerator and denominator array.
impl From<u8> for Rational
[src]
impl From<(u8, u8)> for Rational
[src]
fn from(tuple: (u8, u8)) -> Rational
[src]
Create a new signed rational with the given numerator and denominator tuple.
impl From<[u8; 2]> for Rational
[src]
fn from(array: [u8; 2]) -> Rational
[src]
Create a new signed rational with the given numerator and denominator array.
impl From<i64> for Rational
[src]
impl From<(i64, i64)> for Rational
[src]
fn from(tuple: (i64, i64)) -> Rational
[src]
Creates a new signed rational with the given numerator and denominator tuple.
impl From<[i64; 2]> for Rational
[src]
fn from(array: [i64; 2]) -> Rational
[src]
Creates a new signed rational with the given numerator and denominator array.
impl From<i32> for Rational
[src]
impl From<(i32, i32)> for Rational
[src]
fn from(tuple: (i32, i32)) -> Rational
[src]
Creates a new signed rational with the given numerator and denominator tuple.
impl From<[i32; 2]> for Rational
[src]
fn from(array: [i32; 2]) -> Rational
[src]
Creates a new signed rational with the given numerator and denominator array.
impl From<i16> for Rational
[src]
impl From<(i16, i16)> for Rational
[src]
fn from(tuple: (i16, i16)) -> Rational
[src]
Creates a new signed rational with the given numerator and denominator tuple.
impl From<[i16; 2]> for Rational
[src]
fn from(array: [i16; 2]) -> Rational
[src]
Creates a new signed rational with the given numerator and denominator array.
impl From<i8> for Rational
[src]
impl From<(i8, i8)> for Rational
[src]
fn from(tuple: (i8, i8)) -> Rational
[src]
Creates a new signed rational with the given numerator and denominator tuple.