ratioed

Types

Ratio represents a rational number, i.e. one that can be represented as a fraction of two integers

pub opaque type Ratio

Functions

pub fn add(a: Ratio, b: Ratio) -> Ratio

Add two rationals

pub fn compare(a: Ratio, b: Ratio) -> Order

Compare two rationals

pub fn div(a: Ratio, b: Ratio) -> Ratio

Divide one rational by another, division by 0 will return 0.

pub fn from_f(f: Float) -> Ratio

Create a rational from a float with maximum error of 2^-51

pub fn from_f_epsilon(f: Float, e: Float) -> Ratio

Create a rational from a float with a given maximum error

pub fn from_i(n: Int) -> Ratio

Create a ratio from an integer

pub fn from_i2(numerator n: Int, denominator d: Int) -> Ratio

Create a rational given an integer numerator and denominator

pub fn mul(a: Ratio, b: Ratio) -> Ratio

Multiply two rationals

pub fn sub(a: Ratio, b: Ratio) -> Ratio

Subtract one rational from another

pub fn to_f(ratio: Ratio) -> Float

Convert a rational to a floating point number

pub fn to_i(a: Ratio) -> Int

Convert a rational to an integer, truncating (round towards 0)

pub fn to_string(ratio: Ratio) -> String
Search Document