Class: rat

rat

Rational Number

Constructor

new rat()

Source:
Requires:
  • module:integer

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
Source:

(static, readonly) INFINITESIMAL :rat

Infinitesimal, the limit for approximations
Type:
Properties:
Name Type Description
INFINITESIMAL
Source:

(static, readonly) INFINITY :rat

Infinity, a non-Zero number divided by Zero
Type:
Properties:
Name Type Description
INFINITY
Source:

(static, readonly) INFINULL :rat

Infinull, Zero divided by Zero
Type:
Properties:
Name Type Description
INFINULL
Source:

(static, readonly) MAX_LOOPS

Exit (possibly infinite) loops after this many iterations
Properties:
Name Type Description
MAX_LOOPS
Source:

(static, readonly) NEGONE :rat

Negative One, Zero minus One
Type:
Properties:
Name Type Description
NEGONE
Source:

(static, readonly) ONE :rat

One, the multiplicative identity
Type:
Properties:
Name Type Description
ONE
Source:

(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
Source:

(static, readonly) ZERO :rat

Zero, the additive identity
Type:
Properties:
Name Type Description
ZERO
Source:

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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
Returns:
out
Type
rat

(static) create() → {rat}

Creates a new, empty rat
Source:
Returns:
a new rational number
Type
rat

(static) dec()

Alias for rat.toDecimal
Source:

(static) div()

Alias for rat.divide
Source:

(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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
Returns:
out
Type
rat

(static) mul()

Alias for rat.multiply
Source:

(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
Source:
Returns:
out
Type
rat

(static) neg()

Alias for rat.opposite
Source:

(static) negative()

Alias for rat.opposite
Source:

(static) normalize(out, a) → {rat}

Normalize a rat
Parameters:
Name Type Description
out rat the receiving number
a rat number to normalize
Source:
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
Source:
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
Source:
Returns:
out
Type
rat

(static) pow()

Alias for rat.power
Source:

(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
Source:
Returns:
out
Type
rat

(static) reciprocal()

Alias for rat.invert
Source:

(static) round()

Alias for rat.toInteger
Source:

(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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
Returns:
out
Type
rat

(static) str(a) → {String}

Returns a string representation
Parameters:
Name Type Description
a rat number to represent as a string
Source:
Returns:
string representation of the number
Type
String

(static) sub()

Alias for rat.subtract
Source:

(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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
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
Source:
Returns:
Stern Brocot path
Type
String