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]

[src]

Create a new signed rational with the given numerator and denominator.

[src]

Create a new signed rational with the given unsigned rational and sign.

[src]

Returns the underlying numerator of this rational.

[src]

Returns the underlying numerator of this rational mutably.

[src]

Returns the underlying denominator of this rational.

[src]

Returns the underlying denominator of this rational mutably.

[src]

Returns the underlying sign of this rational.

[src]

Returns the underlying sign of this rational mutably.

[src]

Returns the underlying unsigned rational of this rational.

[src]

Returns the underlying unsigned rational of this rational mutably.

[src]

Returns the underlying unsigned rational of this rational, panicking if sign is negative.

Does not panic in optimized builds.

[src]

Returns the smallest value a signed rational can store.

[src]

Returns the smallest positive value a signed rational can store.

[src]

Returns the largest negative value a signed rational can store.

[src]

Returns the largest value a signed rational can store.

[src]

Returns a signed rational representing NaN.

[src]

Returns a signed rational representing 0.

[src]

Returns a signed rational representing .

[src]

Returns a signed rational representing 1.

[src]

Returns a signed rational representing -1.

[src]

Returns true if this rational is NaN and false otherwise.

[src]

Returns true if this rational is 0 and false otherwise.

[src]

Returns true if this rational is and false otherwise.

[src]

Returns true if this rational is a signed number (not NaN, 0, or ) and false otherwise.

[src]

Returns true if this rational is a negative number and false otherwise.

[src]

Returns the reciprocal of this rational.

[src]

Returns the negative reciprocal of this rational.

[src]

Returns the complexity of this rational (max of absolute values of numerator and denominator).

[src]

Returns true if this rational is a positive number and false otherwise.

[src]

Returns this rational with no fractional component by rounding towards zero.

[src]

Returns this rational with no fractional component by rounding.

[src]

Returns this rational with no fractional component by rounding away from zero.

[src]

Returns this rational without a negative sign.

[src]

Computes self + other, returning None if rounding occurred.

[src]

Computes self - other, returning None if rounding occurred.

[src]

Computes self * other, returning None if rounding occurred.

[src]

Computes self / other, returning None if rounding occurred.

[src]

Computes self % other, returning None if rounding occurred.

Trait Implementations

impl Copy for Rational
[src]

impl Clone for Rational
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Default for Rational
[src]

[src]

Returns the "default value" for a type. Read more

impl PartialEq for Rational
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl PartialOrd for Rational
[src]

[src]

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

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

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]

[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]

[src]

Formats the rational.

Style

All numbers are written as fractions in parentheses (n/d)

impl AddAssign for Rational
[src]

[src]

Performs the += operation.

impl Add for Rational
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl SubAssign for Rational
[src]

[src]

Performs the -= operation.

impl Sub for Rational
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl MulAssign for Rational
[src]

[src]

Performs the *= operation.

impl Mul for Rational
[src]

The resulting type after applying the * operator.

[src]

Performs the * operation.

impl DivAssign for Rational
[src]

[src]

Performs the /= operation.

impl Div for Rational
[src]

The resulting type after applying the / operator.

[src]

Performs the / operation.

impl RemAssign for Rational
[src]

[src]

Performs the %= operation.

impl Rem for Rational
[src]

The resulting type after applying the % operator.

[src]

Performs the % operation.

impl Neg for Rational
[src]

The resulting type after applying the - operator.

[src]

Performs the unary - operation.

impl From<URational> for Rational
[src]

[src]

Create a new signed rational from an unsigned rational.

impl From<(URational, bool)> for Rational
[src]

[src]

Create a new signed rational from an unsigned rational and a sign.

impl From<f64> for Rational
[src]

[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]

[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]

[src]

Create a new signed rational with the given value.

impl From<(u64, u64)> for Rational
[src]

[src]

Create a new signed rational with the given numerator and denominator tuple.

impl From<[u64; 2]> for Rational
[src]

[src]

Create a new signed rational with the given numerator and denominator array.

impl From<u32> for Rational
[src]

[src]

Create a new signed rational with the given value.

impl From<(u32, u32)> for Rational
[src]

[src]

Create a new signed rational with the given numerator and denominator tuple.

impl From<[u32; 2]> for Rational
[src]

[src]

Create a new signed rational with the given numerator and denominator array.

impl From<u16> for Rational
[src]

[src]

Create a new signed rational with the given value.

impl From<(u16, u16)> for Rational
[src]

[src]

Create a new signed rational with the given numerator and denominator tuple.

impl From<[u16; 2]> for Rational
[src]

[src]

Create a new signed rational with the given numerator and denominator array.

impl From<u8> for Rational
[src]

[src]

Create a new signed rational with the given value.

impl From<(u8, u8)> for Rational
[src]

[src]

Create a new signed rational with the given numerator and denominator tuple.

impl From<[u8; 2]> for Rational
[src]

[src]

Create a new signed rational with the given numerator and denominator array.

impl From<i64> for Rational
[src]

[src]

Creates a new signed rational with the given value.

impl From<(i64, i64)> for Rational
[src]

[src]

Creates a new signed rational with the given numerator and denominator tuple.

impl From<[i64; 2]> for Rational
[src]

[src]

Creates a new signed rational with the given numerator and denominator array.

impl From<i32> for Rational
[src]

[src]

Creates a new signed rational with the given value.

impl From<(i32, i32)> for Rational
[src]

[src]

Creates a new signed rational with the given numerator and denominator tuple.

impl From<[i32; 2]> for Rational
[src]

[src]

Creates a new signed rational with the given numerator and denominator array.

impl From<i16> for Rational
[src]

[src]

Creates a new signed rational with the given value.

impl From<(i16, i16)> for Rational
[src]

[src]

Creates a new signed rational with the given numerator and denominator tuple.

impl From<[i16; 2]> for Rational
[src]

[src]

Creates a new signed rational with the given numerator and denominator array.

impl From<i8> for Rational
[src]

[src]

Creates a new signed rational with the given value.

impl From<(i8, i8)> for Rational
[src]

[src]

Creates a new signed rational with the given numerator and denominator tuple.

impl From<[i8; 2]> for Rational
[src]

[src]

Creates a new signed rational with the given numerator and denominator array.