Constructor
new rational()
Chainable wrapper functions for rat.js
- Source:
Requires:
- module:rat
Requires
- module:rat
Methods
(static) fromContinuedFraction(integers) → {rational}
Returns a rational from an array of integers representing a continued fraction
Parameters:
Name | Type | Description |
---|---|---|
integers |
Array | of the continued fraction |
- Source:
Returns:
out
- Type
- rational
(static) fromDecimal(a) → {rational}
Returns a rational from a decimal number
Parameters:
Name | Type | Description |
---|---|---|
a |
Number | decimal number |
- Source:
Returns:
out
- Type
- rational
(static) fromInteger(signed) → {rational}
Returns a rational from an integer
Parameters:
Name | Type | Description |
---|---|---|
signed |
Integer | integer |
- Source:
Returns:
out
- Type
- rational
(static) fromIntegerInverse(signed) → {rational}
Returns a rational from the inverse of an integer
Parameters:
Name | Type | Description |
---|---|---|
signed |
Integer | integer |
- Source:
Returns:
out
- Type
- rational
(static) fromRat(rat) → {rational}
Returns a rational from a rat array
Parameters:
Name | Type | Description |
---|---|---|
rat |
rat |
- Source:
Returns:
out
- Type
- rational
add(b) → {rational}
Add
Parameters:
Name | Type | Description |
---|---|---|
b |
rational | the second operand |
- Source:
Returns:
out
- Type
- rational
div()
Alias for rational.divide
- Source:
divide(b) → {rational}
Divides two rationals
Parameters:
Name | Type | Description |
---|---|---|
b |
rational | the second operand |
- Source:
Returns:
out
- Type
- rational
divided_by()
Alias for rational.divide
- Source:
dump() → {String}
Returns a string with the fraction in various formats
- Source:
Returns:
string various conversions
- Type
- String
invert() → {rational}
Inverts a rational
- Source:
Returns:
out
- Type
- rational
mediant(b) → {rat}
Mediant of two rationals
Parameters:
Name | Type | Description |
---|---|---|
b |
rat | the second operand |
- Source:
Returns:
out the sum of the numerators divided by the sum of the denominators
- Type
- rat
minus()
Alias for rational.subtract
- Source:
mul()
Alias for rational.prototype.multiply
- Source:
multiply(b) → {rat}
Multiplies two rationals
Parameters:
Name | Type | Description |
---|---|---|
b |
rational | the second operand |
- Source:
Returns:
out
- Type
- rat
plus()
Alias for rational.add
- Source:
pow()
Alias for rational.power
- Source:
power(p) → {rat}
Raises a rat to an integer exponent
Parameters:
Name | Type | Description |
---|---|---|
p |
Integer | power to raise the number by |
- Source:
Returns:
out
- Type
- rat
reciprocal()
Alias for rational.invert
- Source:
sub()
Alias for rational.subtract
- Source:
subtract(b) → {rat}
Subtract
Parameters:
Name | Type | Description |
---|---|---|
b |
rat | the second operand |
- Source:
Returns:
out
- Type
- rat
times()
Alias for rational.prototype.multiply
- Source:
toContinuedFraction(maximum) → {Array}
Returns a rational from an array of integers representing a continued fraction
Parameters:
Name | Type | Description |
---|---|---|
maximum |
Integer | number of iterations |
- Source:
Returns:
integers of the continued fraction
- Type
- Array
toDecimal() → {Number}
Returns a decimal approximation
- Source:
Returns:
out
- Type
- Number
toRat() → {rat}
Returns a rat array from a rational
- Source:
Returns:
out
- Type
- rat
toString() → {String}
Expresses the rational in a string as "numerator/denominator"
- Source:
Returns:
numerator/denominator
- Type
- String