Rational
Utilities for working with the Rational type.
Edit on GitHubAdded in 0.6.0
No other changes yet.
from "rational" include Rational
1/2r
3/4r
Functions and constants included in the Rational module.
Added in 0.6.0
No other changes yet.
fromNumber : (number: Number) => Rational
Converts a Number to a Rational.
Parameters:
| param | type | description |
|---|---|---|
number | Number | The value to convert |
number: The value to convertReturns:
| type | description |
|---|---|
Rational | The Number represented as a Rational |
Rational: The Number represented as a RationalAdded in 0.6.0
No other changes yet.
toNumber : (rational: Rational) => Number
Converts a Rational to a Number.
Parameters:
| param | type | description |
|---|---|---|
rational | Rational | The value to convert |
rational: The value to convertReturns:
| type | description |
|---|---|
Number | The Rational represented as a Number |
Number: The Rational represented as a NumberAdded in 0.6.0
No other changes yet.
numerator : (x: Rational) => Number
Finds the numerator of the rational number.
Parameters:
| param | type | description |
|---|---|---|
x | Rational | The rational number to inspect |
x: The rational number to inspectReturns:
| type | description |
|---|---|
Number | The numerator of the rational number |
Number: The numerator of the rational numberAdded in 0.6.0
No other changes yet.
denominator : (x: Rational) => Number
Finds the denominator of the rational number.
Parameters:
| param | type | description |
|---|---|---|
x | Rational | The rational number to inspect |
x: The rational number to inspectReturns:
| type | description |
|---|---|
Number | The denominator of the rational number |
Number: The denominator of the rational numberAdded in 0.6.0
No other changes yet.
toIntegerRatio : (x: Rational) => (Number, Number)
Gets the numerator and denominator of the rational.
Parameters:
| param | type | description |
|---|---|---|
x | Rational | The rational to split |
x: The rational to splitReturns:
| type | description |
|---|---|
(Number, Number) | The numerator and denominator of the rational |
(Number, Number): The numerator and denominator of the rationalExamples:
Rational.toIntegerRatio(1/2r) == (1, 2)
Rational.toIntegerRatio(2/8r) == (1, 4)
Added in 0.6.0
No other changes yet.
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 |
numerator: The numeratordenominator: The denominatorReturns:
| type | description |
|---|---|
Rational | The reduced rational |
Rational: The reduced rationalThrows:
InvalidArgument(String)
- If the numerator is not an integer
- If the denominator is not an integer
Examples:
Rational.fromIntegerRatio(1, 2) == 1/2r
Rational.fromIntegerRatio(2, 8) == 1/4r
Added in 0.6.0
No other changes yet.
(+) : (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 |
x: The first operandy: The second operandReturns:
| type | description |
|---|---|
Rational | The sum of the two operands |
Rational: The sum of the two operandsExamples:
use Rational.{ (+) }
assert 1/2r + 1/4r == 3/4r
Added in 0.6.0
No other changes yet.
(-) : (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 |
x: The first operandy: The second operandReturns:
| type | description |
|---|---|
Rational | The difference of the two operands |
Rational: The difference of the two operandsExamples:
use Rational.{ (-) }
assert 1/2r - 1/4r == 1/4r
Added in 0.6.0
No other changes yet.
(*) : (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 |
x: The first operandy: The second operandReturns:
| type | description |
|---|---|
Rational | The product of the two operands |
Rational: The product of the two operandsExamples:
use Rational.{ (*) }
assert 1/2r * 1/4r == 1/8r
Added in 0.6.0
No other changes yet.
(/) : (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 |
x: The first operandy: The second operandReturns:
| type | description |
|---|---|
Rational | The quotient of the two operands |
Rational: The quotient of the two operandsExamples:
use Rational.{ (/) }
assert 1/2r / 1/4r == 2/1r
Added in 0.6.0
No other changes yet.
(==) : (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 |
x: The first valuey: The second valueReturns:
| type | description |
|---|---|
Bool | true if the first value is equal to the second value or false otherwise |
Bool: true if the first value is equal to the second value or false otherwiseExamples:
use Rational.{ (==) }
assert 1/2r == 1/2r
Added in 0.6.0
No other changes yet.
(!=) : (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 |
x: The first valuey: The second valueReturns:
| type | description |
|---|---|
Bool | true if the first value is not equal to the second value or false otherwise |
Bool: true if the first value is not equal to the second value or false otherwiseExamples:
use Rational.{ (!=) }
assert 1/2r != 1/4r
Added in 0.6.0
No other changes yet.
(<) : (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 |
x: The first valuey: The second valueReturns:
| type | description |
|---|---|
Bool | true if the first value is less than the second value or false otherwise |
Bool: true if the first value is less than the second value or false otherwiseExamples:
use Rational.{ (<) }
assert 1/4r < 1/2r
Added in 0.6.0
No other changes yet.
(>) : (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 |
x: The first valuey: The second valueReturns:
| type | description |
|---|---|
Bool | true if the first value is greater than the second value or false otherwise |
Bool: true if the first value is greater than the second value or false otherwiseExamples:
use Rational.{ (>) }
assert 1/2r > 1/4r
Added in 0.6.0
No other changes yet.
(<=) : (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 |
x: The first valuey: The second valueReturns:
| type | description |
|---|---|
Bool | true if the first value is less than or equal to the second value or false otherwise |
Bool: true if the first value is less than or equal to the second value or false otherwiseExamples:
use Rational.{ (<=) }
assert 1/4r <= 1/2r
use Rational.{ (<=) }
assert 1/2r <= 1/2r
Added in 0.6.0
No other changes yet.
(>=) : (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 |
x: The first valuey: The second valueReturns:
| type | description |
|---|---|
Bool | true if the first value is greater than or equal to the second value or false otherwise |
Bool: true if the first value is greater than or equal to the second value or false otherwiseExamples:
use Rational.{ (>=) }
assert 1/2r >= 1/4r
use Rational.{ (>=) }
assert 1/2r >= 1/2r