Requires
- module:integer
Members
(static, readonly) EPSILON
Machine Epsilon, floats within this distance of eachother are considered equal (to avoid rounding errors)
Properties:
Name | Type | Description |
---|---|---|
EPSILON |
(static, readonly) INFINITESIMAL :rat
Infinitesimal, the limit for approximations
Type:
Properties:
Name | Type | Description |
---|---|---|
INFINITESIMAL |
(static, readonly) INFINITY :rat
Infinity, a non-Zero number divided by Zero
Type:
Properties:
Name | Type | Description |
---|---|---|
INFINITY |
(static, readonly) INFINULL :rat
Infinull, Zero divided by Zero
Type:
Properties:
Name | Type | Description |
---|---|---|
INFINULL |
(static, readonly) MAX_LOOPS
Exit (possibly infinite) loops after this many iterations
Properties:
Name | Type | Description |
---|---|---|
MAX_LOOPS |
(static, readonly) NEGONE :rat
Negative One, Zero minus One
Type:
Properties:
Name | Type | Description |
---|---|---|
NEGONE |
(static, readonly) ONE :rat
One, the multiplicative identity
Type:
Properties:
Name | Type | Description |
---|---|---|
ONE |
(static, readonly) PI :rat
Pi, an approximation of the ratio between a circle's circumference and it's diameter
Type:
Properties:
Name | Type | Description |
---|---|---|
PI |
(static, readonly) ZERO :rat
Zero, the additive identity
Type:
Properties:
Name | Type | Description |
---|---|---|
ZERO |
Methods
(static) abs(out, a) → {rat}
Absolute value of a rat
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | number to take the absolute value of |
Returns:
out
- Type
- rat
(static) add(out, a, b) → {rat}
Adds two rats
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the first operand |
b |
rat | the second operand |
Returns:
out
- Type
- rat
(static) approximates(a, b) → {Bool}
Returns true when the first rat is approximately equal to the second
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | the first operand |
b |
rat | the second operand |
Returns:
true when the difference between the two rats is less than rat.INFINITESIMAL
- Type
- Bool
(static) ceil(a) → {Integer}
Returns the closest integer approximation by rounding up
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | number to round up to the nearest integer |
Returns:
integer approximation of the number
- Type
- Integer
(static) clone(a) → {rat}
Creates a new rat initialized with values from an existing number
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | number to clone |
Returns:
a new rational number
- Type
- rat
(static) copy(out, a) → {rat}
Copy the values from one rat to another
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the source number |
Returns:
out
- Type
- rat
(static) cos(out, a) → {rat}
Parametric cosine: (1 - a²) / (1 + a²)
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | number for which to calculate the parametric cosine |
Returns:
out
- Type
- rat
(static) create() → {rat}
Creates a new, empty rat
Returns:
a new rational number
- Type
- rat
(static) dec()
Alias for rat.toDecimal
(static) div()
Alias for rat.divide
(static) divide(out, a, b) → {rat}
Divides two rats
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the first operand |
b |
rat | the second operand |
Returns:
out
- Type
- rat
(static) dot(a, b) → {Integer}
Calculates the dot product of two rats
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | the first operand |
b |
rat | the second operand |
Returns:
dot product of a and b
- Type
- Integer
(static) dump(a) → {String}
Returns a string with the fraction in various formats
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | number to dump |
Returns:
string various conversions
- Type
- String
(static) equals(a, b) → {Bool}
Returns true when the first rat is equal to the second
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | the first operand |
b |
rat | the second operand |
Returns:
true when the two rats are equal
- Type
- Bool
(static) floor(a) → {Integer}
Returns the closest integer approximation by rounding down
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | number to round down to the nearest integer |
Returns:
integer approximation of the number
- Type
- Integer
(static) fromContinuedFraction(out, integers) → {rat}
Returns a rat from an array of integers representing a continued fraction
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
integers |
Array | of the continued fraction |
Returns:
out
- Type
- rat
(static) fromDecimal(a) → {rat}
Returns a rat from a decimal number, creating a new rat
Parameters:
Name | Type | Description |
---|---|---|
a |
Number | decimal number |
Returns:
out
- Type
- rat
(static) fromDecimal_copy(out, a) → {rat}
Returns a rat from a decimal number, copying to an existing rat
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
Number | decimal number |
Returns:
out
- Type
- rat
(static) fromInteger(signed) → {rat}
Returns a rat from an integer, creating a new rat
Parameters:
Name | Type | Description |
---|---|---|
signed |
Integer | integer |
Returns:
out
- Type
- rat
(static) fromInteger_copy(out, signed) → {rat}
Returns a rat from an integer, copying to an existing rat
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
signed |
Integer | integer |
Returns:
out
- Type
- rat
(static) fromIntegerInverse(signed) → {rat}
Returns a rat from the inverse of an integer, creating a new rat
Parameters:
Name | Type | Description |
---|---|---|
signed |
Integer | integer |
Returns:
out
- Type
- rat
(static) fromIntegerInverse_copy(out, signed) → {rat}
Returns a rat from the inverse of an integer, copying to an existing rat
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
signed |
Integer | integer |
Returns:
out
- Type
- rat
(static) fromRandom(out) → {rat}
Creates a new rat from two random integers
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
Returns:
a random rational number
- Type
- rat
(static) fromValues(n, d) → {rat}
Creates a new rat initialized with the given values
Parameters:
Name | Type | Description |
---|---|---|
n |
Number | Numerator |
d |
Number | Denominator |
Returns:
a new rational number
- Type
- rat
(static) invert(out, a) → {rat}
Inverts a rat
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | number to invert |
Returns:
out
- Type
- rat
(static) isGreaterThan(a, b) → {Bool}
Returns true when the first rat is larger than the second
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | the first operand |
b |
rat | the second operand |
Returns:
true when the first operand is larger
- Type
- Bool
(static) isLessThan(a, b) → {Bool}
Returns true when the first rat is smaller than the second
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | the first operand |
b |
rat | the second operand |
Returns:
true when the first operand is smaller
- Type
- Bool
(static) isNegative(a) → {Bool}
Returns true when the rat is negative
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | the number to check |
Returns:
true when the number is less than zero
- Type
- Bool
(static) max(out, a, b) → {rat}
Returns the maximum of two rats
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the first operand |
b |
rat | the second operand |
Returns:
out
- Type
- rat
(static) mediant(out, a, b) → {rat}
Mediant of two rats
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the first operand |
b |
rat | the second operand |
Returns:
out the sum of the numerators divided by the sum of the denominators
- Type
- rat
(static) min(out, a, b) → {rat}
Returns the minimum of two rats
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the first operand |
b |
rat | the second operand |
Returns:
out
- Type
- rat
(static) mul()
Alias for rat.multiply
(static) multiply(out, a, b) → {rat}
Multiplies two rats
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the first operand |
b |
rat | the second operand |
Returns:
out
- Type
- rat
(static) neg()
Alias for rat.opposite
(static) negative()
Alias for rat.opposite
(static) normalize(out, a) → {rat}
Normalize a rat
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | number to normalize |
Returns:
out
- Type
- rat
(static) nthRoot(out, a, n) → {rat}
Find a rat approximation which equals the input rat when raised to the given integer exponent
Newton's method converges alot faster... could that be used to find the pattern in the SB tree?
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the number to find the root of |
n |
Integer |
Returns:
out
- Type
- rat
(static) opposite(out, a) → {rat}
Negates a rat
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | number to negate |
Returns:
out
- Type
- rat
(static) pow()
Alias for rat.power
(static) power(out, a, p) → {rat}
Raises a rat to an integer exponent
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the number to exponentiate |
p |
Integer | power to raise the number by |
Returns:
out
- Type
- rat
(static) reciprocal()
Alias for rat.invert
(static) round()
Alias for rat.toInteger
(static) scalar_divide(out, a, b) → {rat}
Multiplies a rat's denominator by an integer
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the number to divide |
b |
Integer | amount to divide by |
Returns:
out
- Type
- rat
(static) scalar_multiply(out, a, b) → {rat}
Multiplies a rat's numerator by an integer
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the number to multiply |
b |
Integer | amount to multiply the number by |
Returns:
out
- Type
- rat
(static) set(out, n, d) → {rat}
Set the components of a rat to the given values
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
n |
Number | Numerator |
d |
Number | Denominator |
Returns:
out
- Type
- rat
(static) sin(out, a) → {rat}
Parametric sine: 2a / (1 + a²)
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | number for which to calculate the parametric sine |
Returns:
out
- Type
- rat
(static) sqrt(out, a) → {rat}
Find a rational number which approximates the input number when multiplied by itself
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the number to find the root of |
Returns:
out
- Type
- rat
(static) str(a) → {String}
Returns a string representation
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | number to represent as a string |
Returns:
string representation of the number
- Type
- String
(static) sub()
Alias for rat.subtract
(static) subtract(out, a, b) → {rat}
Subtracts two rats
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | the first operand |
b |
rat | the second operand |
Returns:
out
- Type
- rat
(static) tan(out, a) → {rat}
Parametric tangent: sin(a) / cos(a)
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
rat | number for which to calculate the parametric tangent |
Returns:
out
- Type
- rat
(static) toBabylonian(a) → {String}
Returns a Babylonian representation (base 60)
The returned string can be evaluated in "calc - arbitrary precision calculator"
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | number to represent as a Babylonian fraction |
Returns:
string containing the decimal representations of the base 60 digits and their powers, in "calc" format
- Type
- String
(static) toContinuedFraction(a, maximum) → {Array}
Returns an array of integers representing the continued fraction
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | number to convert to a continued fraction |
maximum |
Integer | number of iterations |
Returns:
integers of the continued fraction
- Type
- Array
(static) toDecimal(a) → {Float}
Returns a decimal approximation
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | number to approximate as a decimal |
Returns:
decimal approximation of the number
- Type
- Float
(static) toEgyptian(a) → {String}
Returns an Egyptian representation
The returned string can be evaluated in "calc - arbitrary precision calculator"
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | number to represent as an Egyptian fraction |
Returns:
string representing the most simple sum of fractions having a numerator of one, in "calc" format
- Type
- String
(static) toInteger(a) → {Integer}
Returns the closest integer approximation
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | number to round to the nearest integer |
Returns:
integer approximation of the number
- Type
- Integer
(static) traceSternBrocot(a) → {String}
Returns a string of L's and R's representing the Stern Brocot path
Parameters:
Name | Type | Description |
---|---|---|
a |
rat | number to trace in the Stern Brocot tree |
Returns:
Stern Brocot path
- Type
- String