hugenumberjs
v2.0.0
Published
A library for storing extremely large numbers in JavaScript.
Maintainers
Readme
hugenumberjs
hugenumberjs is a library for storing extremely large numbers (up to {10, 1000[2]2} in Bird's array notation or approximately f_ω^ω(1000) in the fast-growing hierarchy) in JavaScript. Supports both Node and browser. It can be used for googology (the study of large numbers) and complex incremental games. It vastly exceeds the limitations of the next-best libraries for this purpose such as https://github.com/Naruyoko/ExpantaNum.js/tree/master but may be slow. You may want to use a simpler library like ExpantaNum.js or https://github.com/Patashu/break_eternity.js if you are not doing as heavy-duty large numbers. There is also some support for very small (near-zero) numbers in this library but it is much more limited than the very large number support, going down to approximately 10^(-(1.8*10^308)).
Numbers are represented in [https://www.mrob.com/users/chrisb/Linear_Array_Notation.pdf](Bird's Linear Array Notation) (or equivalently, linear BEAF), although it is a modified version to support non-integer arguments. Internally this is stored as a property called array, where the first argument is omitted and is an implicit 10 since this is 10-based. Nesting arrays are not allowed (aside from a limited nesting capability provided by the blan10 method)–all elements are stored as base JavaScript numbers and never HugeNumbers. There is also a signproperty equal to 1, 0, or -1 to support 0 and negative numbers. So for example, the number -{10,100,1,1,2}in BLAN would be represented by having the array property set to [100,1,1,2] and the sign property set to -1 since it is a negative number.
Changelog
- 1.0: Initial release which used chained arrow notation
- 2.0: New release which is basically a complete overhaul to use BLAN
Continuous Bird's array notation definition
Numbers are represented in [https://www.mrob.com/users/chrisb/Linear_Array_Notation.pdf](Bird's Linear Array Notation) (or equivalently, linear BEAF), although it is a modified version to support non-integer arguments. The formal googological definition of this modified version of BLAN has been put here for convenience.
Let @ represent an arbitrary (possibly empty) comma-separated list of real numbers greater than or equal to 1. An expression is of the form {@}.
Let a, where a is a real number greater than or equal to 1, and b is a positive integer, represent the comma-separated list of a repeated b times.
To evaluate an expression, use the following rules:
- {} = 1
- {a} = a
- {a, b} = a^b
- {@, 1} = {@}
- {a, 1, @} = a
- {a, b, 1, d, @} = {a, b, 1<n + 1>, @}^(2 - d) * {a, b, 1, 2, @}^(d - 1) if 1 < d < 2
- {a, b, 1, d, @} = {a<n + 1>, a^(b - 1), d - 1, @} if 1 < b < 2 and d > 2
- {a, b, 1, d, @} = {a<n + 1>, {a, b - 1, 1, d, @}, d - 1, @} if b > 2 and d > 2
- {a, b, c, @} = {a, b, 1, @}^(2 - c) * {a, b, 1, @}^(c - 1) 1 < c < 2
- {a, b, c, @} = {a, a^(b - 1), c - 1, @} if 1 < b < 2 and c > 2
- {a, b, c, @} = {a, {a, b - 1, c, @}, c - 1, @} if b > 2 and c > 2
Method documentation
constructor(sign, array): This is the constructor based on the internal representation, taking in thesignandarraypropertise as described earlier. Note that the array is "normalized" so for example inputting the array[2,2]would have it automatically simplify to[10]since {10,2,2} = {10,10} = 10^10.static fromNumber(num): Converts from a standard (built-in) number to aHugeNumberobject.static fromString(str): Converts from a string to aHugeNumberobject (currently can include ordinary numbers, scientific notation like1e+1000, scientific notation with nested exponents like1e+1e+1000, but not up-arrow notation, BLAN or anything else)clone(): Returns a cloned object ofthis.abs(): Returns the absolute value ofthis.neg(): Returns the negation ofthis.add(other): Returns the sum ofthisandother.sub(other): Returns the difference ofthisandother.mul(other): Returns the product ofthisandother.div(other): Returns the quotient ofthisandother.mod(other): Returns the modulo ofthisandother.exp10(): Returns the base-10 exponential function ofthis.exp(): Returns the base-e exponential function ofthis.pow(other): Returnsthisraised to the power ofother.sqrt(): Returns the square root ofthis.cbrt(): Returns the cube root ofthis.log10(): Returns the base-10 logarithm ofthis.log(): Returns the natural logarithm ofthis.logb(b): Returns the base-blogarithm ofthis.sin(): Returns the sine ofthis.cos(): Returns the cosine ofthis.tan(): Returns the tangent ofthis.asin(): Returns the inverse sine ofthis.acos(): Returns the inverse cosine ofthis.atan(): Returns the inverse tangent ofthis.sinh(): Returns the hyperbolic sine ofthis.cosh(): Returns the hyperbolic cosine ofthis.tanh(): Returns the hyperbolic tangent ofthis.asinh(): Returns the inverse hyperbolic sine ofthis.acosh(): Returns the inverse hyperbolic cosine ofthis.atanh(): Returns the inverse hyperbolic tangent ofthis.floor(): Returns the floor function ofthis.ceil(): Returns the ceiling function ofthis.round(): Returns the round to nearest integer function ofthis.trunc(): Returns the truncate function ofthis.tetr10(): Returns 10 tetrated tothis. If you want to do pentation or higher with base 10 see theblan10method.tetr(other): Returnsthistetrated toother(may be buggy or slow for bases very close to e^(1/e) ≈ 1.445).lambertw(): Returns the Lambert W function ofthis.ssqrt(): Returns the super-square root ofthis.slog10(other): Returns the base-10 superlogarithm ofthis.slogb(b): Returns the base-bsuperlogarithm ofthis(may be buggy or slow for bases very close to e^(1/e) ≈ 1.445).blan10(array): Returns {10, this, array[0], array[1], array[2], array[3]....} in Bird's Linear Array Notation. For example:HugeNumber.fromNumber(11).blan10([12,13])would return {10,11,12,13} in Bird's Linear Array Notation. The elements of the array have to be standard numbers notHugeNumbers. This is the only way to do pentation or higher currently, and it is only base 10. 10 pentated to isx.blan10([3])since it's {10,x,3} in BLAN.cmp(other): "Three-way comparison" opearator (returns -1 ifthis < other, 0 ifthis === other, 1 ifthis > other)eq(other): Equal tone(other): Not equal tolt(other): Less thanle(other): Less than or equalgt(other): Greater thange(other): Greater than or equalmin(other): Returns the minimum ofthisandother.max(other): Returns the maximum ofthisandother.toNumber(): Converts aHugeNumberobject to a standard (built-in) number. (if theHugeNumberis too large to be converted to a standard number, this will returnInfinity)toString(): Converts aHugeNumberobject to a string representation.
