rational

Types

pub opaque type Rational

Functions

pub fn absolute_value(a: Rational) -> Rational
pub fn add(a: Rational, b: Rational) -> Rational

Adds two rational numbers.

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

Compares two rational numbers, returning an Order type that describes their relationship

pub fn divide(a: Rational, b: Rational) -> Result(Rational, Nil)
pub fn from_float(from f: Float, to_nearest inc: Rational) -> Rational

Creates a new rational number from a float, rounding it to the nearest rational increment.

pub fn from_int(from: Int) -> Rational

Creates a new rational number from an integer.

pub fn multiply(a: Rational, b: Rational) -> Rational

Multiplies two rational numbers.

pub fn new(num: Int, den: Int) -> Result(Rational, Nil)

Creates a new rational number from a numerator (top of the fraction) and denominator (bottom).

pub fn new_improper(whole: Int, num: Int, den: Int) -> Result(
  Rational,
  Nil,
)

Creates a new rational number from an improper fraction, which has a whole number part as well as a numerator and denominator.

pub fn pow(a: Rational, n: Int) -> Rational
pub fn reciprocal(a: Rational) -> Rational
pub fn subtract(a: Rational, b: Rational) -> Rational

Subtracts two rational numbers.

pub fn to_float(r: Rational) -> Float

Returns the neaerest float to the rational number.

pub fn to_mixed_fraction(r: Rational) -> #(Int, Rational)

Takes a rational number and returns it as a tuple representing a mixed fraction, with a whole part and a fractional part.

pub fn truncate(r: Rational) -> Int
Search Document