Struct extended_rational::URational [] [src]

pub struct URational { /* fields omitted */ }

A type representing an unsigned projectively-extended rational number

Subtracting a large number from a smaller one always returns 0 unless the larger number is .

Examples

use extended_rational::URational;

let a = URational::new(3, 17);
let b = URational::new(4, 7);

assert_eq!(a+b, URational::new(89, 119));

Use the uratio! macro for more convenient use.

let a = uratio!(3, 17);
let b = uratio!(4, 7);

Or for easy conversions from primitive types.

let a = uratio!(343.863);
let b = uratio!(2u8);

Methods

impl URational
[src]

[src]

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

[src]

Returns the numerator of this rational.

[src]

Returns the numerator of this rational mutably.

[src]

Returns the denominator of this rational.

[src]

Returns the denominator of this rational mutably.

[src]

Returns the smallest value an unsigned rational can store.

[src]

Returns the smallest non-zero value an unsigned rational can store.

[src]

Returns the largest value an unsigned rational can store.

[src]

Returns an unsigned rational representing NaN.

[src]

Returns an unsigned rational representing 0.

[src]

Returns an unsigned rational representing .

[src]

Returns an unsigned 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 the reciprocal of this rational.

[src]

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

[src]

Returns this rational with no fractional component by rounding down.

[src]

Returns this rational with no fractional component by rounding.

[src]

Returns this rational with no fractional component by rounding up.

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

impl Clone for URational
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Default for URational
[src]

[src]

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

impl PartialEq for URational
[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 URational
[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 URational
[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 URational
[src]

[src]

Formats the rational.

Style

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

impl AddAssign for URational
[src]

[src]

Performs the += operation.

impl Add for URational
[src]

The resulting type after applying the + operator.

[src]

Performs the + operation.

impl SubAssign for URational
[src]

[src]

Performs the -= operation.

impl Sub for URational
[src]

The resulting type after applying the - operator.

[src]

Performs the - operation.

impl MulAssign for URational
[src]

[src]

Performs the *= operation.

impl Mul for URational
[src]

The resulting type after applying the * operator.

[src]

Performs the * operation.

impl DivAssign for URational
[src]

[src]

Performs the /= operation.

impl Div for URational
[src]

The resulting type after applying the / operator.

[src]

Performs the / operation.

impl RemAssign for URational
[src]

[src]

Performs the %= operation.

impl Rem for URational
[src]

The resulting type after applying the % operator.

[src]

Performs the % operation.

impl From<u64> for URational
[src]

[src]

Create a new unsigned rational with the given value.

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

[src]

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

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

[src]

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

impl From<u32> for URational
[src]

[src]

Create a new unsigned rational with the given value.

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

[src]

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

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

[src]

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

impl From<u16> for URational
[src]

[src]

Create a new unsigned rational with the given value.

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

[src]

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

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

[src]

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

impl From<u8> for URational
[src]

[src]

Create a new unsigned rational with the given value.

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

[src]

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

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

[src]

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