Requires
- module:bigint
Members
(static, readonly) EPSILON
Machine Epsilon, floats within this distance of each other are considered equal
Properties:
Name | Type | Description |
---|---|---|
EPSILON |
(static, readonly) INFINITESIMAL
Infinitesimal, the limit for approximations
Properties:
Name | Type | Description |
---|---|---|
INFINITESIMAL |
(static, readonly) INFINITY
Infinity, a non-Zero number divided by Zero
Properties:
Name | Type | Description |
---|---|---|
INFINITY |
(static, readonly) INFINULL
Infinull, Zero divided by Zero
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
Negative One, Zero minus One
Properties:
Name | Type | Description |
---|---|---|
NEGONE |
(static, readonly) ONE
One, the multiplicative identity
Properties:
Name | Type | Description |
---|---|---|
ONE |
(static, readonly) PI
Pi, an approximation of the ratio between a circle's circumference and it's diameter
Properties:
Name | Type | Description |
---|---|---|
PI |
(static, readonly) ZERO
Zero, the additive identity
Properties:
Name | Type | Description |
---|---|---|
ZERO |
Methods
(static) abs(out, a) → {bigrat}
Absolute value of a bigrat
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | number to take the absolute value of |
Returns:
out
- Type
- bigrat
(static) add(out, a, b) → {bigrat}
Adds two bigrats
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | the first operand |
b |
bigrat | the second operand |
Returns:
out
- Type
- bigrat
(static) approximates(a, b) → {Bool}
Returns true when the first bigrat is approximately equal to the second
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | the first operand |
b |
bigrat | the second operand |
Returns:
true when the difference between the two bigrats is less than bigrat.INFINITESIMAL
- Type
- Bool
(static) ceil(a) → {Integer}
Returns the closest integer approximation by rounding up
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | number to round up to the nearest integer |
Returns:
integer approximation of the number
- Type
- Integer
(static) clone(a) → {bigrat}
Creates a new bigrat initialized with values from an existing number
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | number to clone |
Returns:
a new bigrational number
- Type
- bigrat
(static) copy(out, a) → {bigrat}
Copy the values from one bigrat to another
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | the source number |
Returns:
out
- Type
- bigrat
(static) cos(out, a) → {bigrat}
Parametric cosine: (1 - a²) / (1 + a²)
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | number for which to calculate the parametric cosine |
Returns:
out
- Type
- bigrat
(static) create() → {bigrat}
Creates a new, empty bigrat
Returns:
a new bigrational number
- Type
- bigrat
(static) dec()
Alias for bigrat.toDecimal
(static) div()
Alias for bigrat.divide
(static) divide(out, a, b) → {bigrat}
Divides two bigrats
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | the first operand |
b |
bigrat | the second operand |
Returns:
out
- Type
- bigrat
(static) dot(a, b) → {Integer}
Calculates the dot product of two bigrats
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | the first operand |
b |
bigrat | 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 |
bigrat | number to dump |
Returns:
string various conversions
- Type
- String
(static) equals(a, b) → {Bool}
Returns true when the first bigrat is equal to the second
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | the first operand |
b |
bigrat | the second operand |
Returns:
true when the two bigrats are equal
- Type
- Bool
(static) floor(a) → {Integer}
Returns the closest integer approximation by rounding down
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | number to round down to the nearest integer |
Returns:
integer approximation of the number
- Type
- Integer
(static) fromContinuedFraction(out, integers) → {bigrat}
Returns a bigrat from an array of integers representing a continued fraction
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
integers |
Array | of the continued fraction |
Returns:
out
- Type
- bigrat
(static) fromDecimal(a) → {bigrat}
Returns a bigrat from a decimal number, creating a new bigrat
Parameters:
Name | Type | Description |
---|---|---|
a |
Number | decimal number |
Returns:
out
- Type
- bigrat
(static) fromDecimal_copy(out, a) → {bigrat}
Returns a bigrat from a decimal number, copying to an existing bigrat
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
Number | decimal number |
Returns:
out
- Type
- bigrat
(static) fromFactorial(out, n) → {bigrat}
Return the factorial of n as a big rational number
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
n |
Integer |
Returns:
factorial of n
- Type
- bigrat
(static) fromInteger(signed) → {bigrat}
Returns a bigrat from an integer, creating a new bigrat
Parameters:
Name | Type | Description |
---|---|---|
signed |
Integer | integer |
Returns:
out
- Type
- bigrat
(static) fromInteger_copy(out, signed) → {bigrat}
Returns a bigrat from an integer, copying to an existing bigrat
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
signed |
Integer | integer |
Returns:
out
- Type
- bigrat
(static) fromIntegerInverse(signed) → {bigrat}
Returns a bigrat from the inverse of an integer, creating a new bigrat
Parameters:
Name | Type | Description |
---|---|---|
signed |
Integer | integer |
Returns:
out
- Type
- bigrat
(static) fromIntegerInverse_copy(out, signed) → {bigrat}
Returns a bigrat from the inverse of an integer, copying to an existing bigrat
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
signed |
Integer | integer |
Returns:
out
- Type
- bigrat
(static) fromRandom(out) → {bigrat}
Creates a new bigrat from two random integers
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
Returns:
a random bigrational number
- Type
- bigrat
(static) fromRat(out, a) → {bigrat}
Returns a bigrat from a rat
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
rat | number to convert |
Returns:
out
- Type
- bigrat
(static) fromValues(n, d) → {bigrat}
Creates a new bigrat initialized with the given values
Parameters:
Name | Type | Description |
---|---|---|
n |
Number | Numerator |
d |
Number | Denominator |
Returns:
a new bigrational number
- Type
- bigrat
(static) invert(out, a) → {bigrat}
Inverts a bigrat
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | number to invert |
Returns:
out
- Type
- bigrat
(static) isGreaterThan(a, b) → {Bool}
Returns true when the first bigrat is larger than the second
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | the first operand |
b |
bigrat | the second operand |
Returns:
true when the first operand is larger
- Type
- Bool
(static) isLessThan(a, b) → {Bool}
Returns true when the first bigrat is smaller than the second
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | the first operand |
b |
bigrat | the second operand |
Returns:
true when the first operand is smaller
- Type
- Bool
(static) isNegative(a) → {Bool}
Returns true when the bigrat is negative
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | the number to check |
Returns:
true when the number is less than zero
- Type
- Bool
(static) max(out, a, b) → {bigrat}
Returns the maximum of two bigrats
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | the first operand |
b |
bigrat | the second operand |
Returns:
out
- Type
- bigrat
(static) mediant(out, a, b) → {bigrat}
Mediant of two bigrats
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | the first operand |
b |
bigrat | the second operand |
Returns:
out the sum of the numerators divided by the sum of the denominators
- Type
- bigrat
(static) min(out, a, b) → {bigrat}
Returns the minimum of two bigrats
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | the first operand |
b |
bigrat | the second operand |
Returns:
out
- Type
- bigrat
(static) mul()
Alias for bigrat.multiply
(static) multiply(out, a, b) → {bigrat}
Multiplies two bigrats
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | the first operand |
b |
bigrat | the second operand |
Returns:
out
- Type
- bigrat
(static) neg()
Alias for bigrat.opposite
(static) negative()
Alias for bigrat.opposite
(static) normalize(out, a) → {bigrat}
Normalize a bigrat
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | number to normalize |
Returns:
out
- Type
- bigrat
(static) nthRoot(out, a, n) → {bigrat}
Find a bigrat approximation which equals the input bigrat 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 |
bigrat | the receiving number |
a |
bigrat | the number to find the root of |
n |
Integer |
Returns:
out
- Type
- bigrat
(static) opposite(out, a) → {bigrat}
Negates a bigrat
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | number to negate |
Returns:
out
- Type
- bigrat
(static) pow()
Alias for bigrat.power
(static) power(out, a, p) → {bigrat}
Raises a bigrat to an integer exponent
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | the number to exponentiate |
p |
Integer | power to raise the number by |
Returns:
out
- Type
- bigrat
(static) reciprocal()
Alias for bigrat.invert
(static) round()
Alias for bigrat.toInteger
(static) scalar_divide(out, a, b) → {bigrat}
Multiplies a bigrat's denominator by an integer
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | the number to divide |
b |
Integer | amount to divide by |
Returns:
out
- Type
- bigrat
(static) scalar_multiply(out, a, b) → {bigrat}
Multiplies a bigrat's numerator by an integer
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | the number to multiply |
b |
Integer | amount to multiply the number by |
Returns:
out
- Type
- bigrat
(static) set(out, n, d) → {bigrat}
Set the components of a bigrat to the given values
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
n |
BigInteger | Numerator |
d |
BigInteger | Denominator |
Returns:
out
- Type
- bigrat
(static) sin(out, a) → {bigrat}
Parametric sine: 2a / (1 + a²)
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | number for which to calculate the parametric sine |
Returns:
out
- Type
- bigrat
(static) sqrt(out, a) → {bigrat}
Find a bigrational number which approximates the input number when multiplied by itself
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | the number to find the root of |
Returns:
out
- Type
- bigrat
(static) str(a) → {String}
Returns a string representation
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | number to represent as a string |
Returns:
string representation of the number
- Type
- String
(static) sub()
Alias for bigrat.subtract
(static) subtract(out, a, b) → {bigrat}
Subtracts two bigrats
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | the first operand |
b |
bigrat | the second operand |
Returns:
out
- Type
- bigrat
(static) tan(out, a) → {bigrat}
Parametric tangent: sin(a) / cos(a)
Parameters:
Name | Type | Description |
---|---|---|
out |
bigrat | the receiving number |
a |
bigrat | number for which to calculate the parametric tangent |
Returns:
out
- Type
- bigrat
(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 |
bigrat | 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) toBigInteger(a) → {BigInteger}
Returns a big integer approximation (truncated towards zero)
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | number to round |
Returns:
big integer approximation of the number
- Type
- BigInteger
(static) toContinuedFraction(a, maximum) → {Array}
Returns an array of integers representing the continued fraction
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | 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 |
bigrat | 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 |
bigrat | 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 a big integer approximation (truncated towards zero)
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | number to round |
Returns:
native integer approximation of the number
- Type
- Integer
(static) toRat(out, a) → {rat}
Returns a rat from a bigrat
Parameters:
Name | Type | Description |
---|---|---|
out |
rat | the receiving number |
a |
bigrat | number to truncate |
Returns:
out
- Type
- rat
(static) traceSternBrocot(a) → {String}
Returns a string of L's and R's representing the Stern Brocot path
Parameters:
Name | Type | Description |
---|---|---|
a |
bigrat | number to trace in the Stern Brocot tree |
Returns:
Stern Brocot path
- Type
- String