Rational

GitHub   Edit on GitHub

Utilities for working with the Rational type.

Added in 0.6.0 No other changes yet.
1
from "rational" include Rational
1
1/2r
1
3/4r

Values

Functions and constants included in the Rational module.

Rational.fromNumber

Added in 0.6.0 No other changes yet.
1
fromNumber : (number: Number) => Rational

Converts a Number to a Rational.

Parameters:

param type description
number Number The value to convert

Returns:

type description
Rational The Number represented as a Rational

Rational.toNumber

Added in 0.6.0 No other changes yet.
1
toNumber : (rational: Rational) => Number

Converts a Rational to a Number.

Parameters:

param type description
rational Rational The value to convert

Returns:

type description
Number The Rational represented as a Number

Rational.numerator

Added in 0.6.0 No other changes yet.
1
numerator : (x: Rational) => Number

Finds the numerator of the rational number.

Parameters:

param type description
x Rational The rational number to inspect

Returns:

type description
Number The numerator of the rational number

Rational.denominator

Added in 0.6.0 No other changes yet.
1
denominator : (x: Rational) => Number

Finds the denominator of the rational number.

Parameters:

param type description
x Rational The rational number to inspect

Returns:

type description
Number The denominator of the rational number

Rational.toIntegerRatio

Added in 0.6.0 No other changes yet.
1
toIntegerRatio : (x: Rational) => (Number, Number)

Gets the numerator and denominator of the rational.

Parameters:

param type description
x Rational The rational to split

Returns:

type description
(Number, Number) The numerator and denominator of the rational

Examples:

1
Rational.toIntegerRatio(1/2r) == (1, 2)
1
Rational.toIntegerRatio(2/8r) == (1, 4)

Rational.fromIntegerRatio

Added in 0.6.0 No other changes yet.
1
fromIntegerRatio : (numerator: Number, denominator: Number) => Rational

Creates a rational from a numerator and denominator.

Parameters:

param type description
numerator Number The numerator
denominator Number The denominator

Returns:

type description
Rational The reduced rational

Throws:

InvalidArgument(String)

  • If the numerator is not an integer
  • If the denominator is not an integer

Examples:

1
Rational.fromIntegerRatio(1, 2) == 1/2r
1
Rational.fromIntegerRatio(2, 8) == 1/4r

Rational.(+)

Added in 0.6.0 No other changes yet.
1
(+) : (x: Rational, y: Rational) => Rational

Computes the sum of its operands.

Parameters:

param type description
x Rational The first operand
y Rational The second operand

Returns:

type description
Rational The sum of the two operands

Examples:

1
2
use Rational.{ (+) }
assert 1/2r + 1/4r == 3/4r

Rational.(-)

Added in 0.6.0 No other changes yet.
1
(-) : (x: Rational, y: Rational) => Rational

Computes the difference of its operands.

Parameters:

param type description
x Rational The first operand
y Rational The second operand

Returns:

type description
Rational The difference of the two operands

Examples:

1
2
use Rational.{ (-) }
assert 1/2r - 1/4r == 1/4r

Rational.(*)

Added in 0.6.0 No other changes yet.
1
(*) : (x: Rational, y: Rational) => Rational

Computes the product of its operands.

Parameters:

param type description
x Rational The first operand
y Rational The second operand

Returns:

type description
Rational The product of the two operands

Examples:

1
2
use Rational.{ (*) }
assert 1/2r * 1/4r == 1/8r

Rational.(/)

Added in 0.6.0 No other changes yet.
1
(/) : (x: Rational, y: Rational) => Rational

Computes the quotient of its operands.

Parameters:

param type description
x Rational The first operand
y Rational The second operand

Returns:

type description
Rational The quotient of the two operands

Examples:

1
2
use Rational.{ (/) }
assert 1/2r / 1/4r == 2/1r

Rational.(==)

Added in 0.6.0 No other changes yet.
1
(==) : (x: Rational, y: Rational) => Bool

Checks if the first value is equal to the second value.

Parameters:

param type description
x Rational The first value
y Rational The second value

Returns:

type description
Bool true if the first value is equal to the second value or false otherwise

Examples:

1
2
use Rational.{ (==) }
assert 1/2r == 1/2r

Rational.(!=)

Added in 0.6.0 No other changes yet.
1
(!=) : (x: Rational, y: Rational) => Bool

Checks if the first value is not equal to the second value.

Parameters:

param type description
x Rational The first value
y Rational The second value

Returns:

type description
Bool true if the first value is not equal to the second value or false otherwise

Examples:

1
2
use Rational.{ (!=) }
assert 1/2r != 1/4r

Rational.(<)

Added in 0.6.0 No other changes yet.
1
(<) : (x: Rational, y: Rational) => Bool

Checks if the first value is less than the second value.

Parameters:

param type description
x Rational The first value
y Rational The second value

Returns:

type description
Bool true if the first value is less than the second value or false otherwise

Examples:

1
2
use Rational.{ (<) }
assert 1/4r < 1/2r

Rational.(>)

Added in 0.6.0 No other changes yet.
1
(>) : (x: Rational, y: Rational) => Bool

Checks if the first value is greater than the second value.

Parameters:

param type description
x Rational The first value
y Rational The second value

Returns:

type description
Bool true if the first value is greater than the second value or false otherwise

Examples:

1
2
use Rational.{ (>) }
assert 1/2r > 1/4r

Rational.(<=)

Added in 0.6.0 No other changes yet.
1
(<=) : (x: Rational, y: Rational) => Bool

Checks if the first value is less than or equal to the second value.

Parameters:

param type description
x Rational The first value
y Rational The second value

Returns:

type description
Bool true if the first value is less than or equal to the second value or false otherwise

Examples:

1
2
use Rational.{ (<=) }
assert 1/4r <= 1/2r
1
2
use Rational.{ (<=) }
assert 1/2r <= 1/2r

Rational.(>=)

Added in 0.6.0 No other changes yet.
1
(>=) : (x: Rational, y: Rational) => Bool

Checks if the first value is greater than or equal to the second value.

Parameters:

param type description
x Rational The first value
y Rational The second value

Returns:

type description
Bool true if the first value is greater than or equal to the second value or false otherwise

Examples:

1
2
use Rational.{ (>=) }
assert 1/2r >= 1/4r
1
2
use Rational.{ (>=) }
assert 1/2r >= 1/2r
This is a notification!