Skip to content

Commit

Permalink
Merge pull request #156 from MathCookie17/master
Browse files Browse the repository at this point in the history
Possibly v1.4
  • Loading branch information
Patashu authored Nov 9, 2023
2 parents 4878c10 + dcf3117 commit 6169647
Show file tree
Hide file tree
Showing 8 changed files with 2,514 additions and 1,842 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A Javascript numerical library to represent numbers as large as 10^^1e308 and as 'small' as 10^-(10^^1e308). This is a sequel to break_infinity.js, my other library which maxes out at 1e1e308 ( https://github.com/Patashu/break_infinity.js ) and its C# port ( https://github.com/Razenpok/BreakInfinity.cs ). Despite handling a wider range of numbers, execution time is comparable (within 2x/0.5x as fast as break_infinity.js in testing) and it has the same interface, so it can be used as a drop-in replacement for break_infinity.js and decimal.js.

Now with arbitrary real height and base handling in your favourite hyper 4 operators (tetrate, iterated exponentiation, iterated logarithm, super logarithm, super square root) and even in pentate (if you want to do that for some reason)! Using the linear approximation. (Analytical approximation is too hard for me atm.)
Now with arbitrary real height and base handling in your favourite hyper 4 operators (tetrate, iterated exponentiation, iterated logarithm, super logarithm, super root) and even in pentate (if you want to do that for some reason)! Using the linear approximation. (Analytical approximation is too hard for me atm.)

The internal representation is as follows: `Decimal.fromComponents(sign, layer, mag)` === `sign*10^10^10^ ... (layer times) mag`. So a layer 0 number is just `sign*mag`, a layer 1 number is `sign*10^mag`, a layer 2 number is `sign*10^10^mag`, and so on. If `layer > 0` and `mag < 0`, then the number's exponent is negative, e.g. `sign*10^-10^10^10^ ... mag`.

Expand All @@ -14,7 +14,7 @@ Create a Decimal with `new Decimal(String or Number or Decimal)` or with `Decima

IMPORTANT NOTE TO PEOPLE CONVERTING FROM break_infinity.js: log/log2/log10/ln now return Decimal not Number! You'll also need to reconsider your string parsing/displaying functions and consider moving e/exponent calls to absLog10. Support for very small numbers has finally been added, so things like tickspeed multiplier being 1e-400 will be fine now!

Functions you can call include `abs, neg, round, floor, ceil, trunc, add, sub, mul, div, recip, cmp, cmpabs, max, min, maxabs, minabs, log, log10, ln, pow, root, factorial, gamma, exp, sqrt, tetrate, iteratedexp, iteratedlog, layeradd10, layeradd, slog, ssqrt, lambertw, pentate` and more! Javascript operators like `+` and `*` do not work - you need to call the equivalent functions instead.
Functions you can call include `abs, neg, round, floor, ceil, trunc, add, sub, mul, div, recip, mod, cmp, cmpabs, max, min, maxabs, minabs, log, log10, ln, pow, root, factorial, gamma, exp, sqrt, tetrate, iteratedexp, iteratedlog, layeradd10, layeradd, slog, ssqrt, lambertw, linear_sroot, pentate` and more! Javascript operators like `+` and `*` do not work - you need to call the equivalent functions instead.

Accepted input formats to new Decimal or Decimal.fromString:

Expand All @@ -33,6 +33,7 @@ eeee... (N es) X === 10^10^10^ ... (N 10^s) X
N PT X === 10^10^10^ ... (N 10^s) X
N PT (X) === 10^10^10^ ... (N 10^s) X
NpX === 10^10^10^ ... (N 10^s) X
XFN === 10^10^10^ ... (N 10^s) X
X^Y === X^Y
X^^N === X^X^X^ ... (N X^s) 1
X^^N;Y === X^X^X^ ... (N X^s) Y
Expand Down
1,250 changes: 659 additions & 591 deletions break_eternity.cjs.js

Large diffs are not rendered by default.

1,250 changes: 659 additions & 591 deletions break_eternity.esm.js

Large diffs are not rendered by default.

1,250 changes: 659 additions & 591 deletions break_eternity.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion break_eternity.min.js

Large diffs are not rendered by default.

46 changes: 27 additions & 19 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export declare type CompareResult = -1 | 0 | 1;
export declare type DecimalSource = Decimal | number | string;
export type CompareResult = -1 | 0 | 1;
export type DecimalSource = Decimal | number | string;
/**
* The Decimal's value is simply mantissa * 10^exponent.
* The value of the Decimal is sign * 10^10^10...^mag, with (layer) 10s. If the layer is not 0, then negative mag means it's the reciprocal of the corresponding number with positive mag.
*/
export default class Decimal {
static readonly dZero: Decimal;
Expand Down Expand Up @@ -70,6 +70,9 @@ export default class Decimal {
static recip(value: DecimalSource): Decimal;
static reciprocal(value: DecimalSource): Decimal;
static reciprocate(value: DecimalSource): Decimal;
static mod(value: DecimalSource, other: DecimalSource): Decimal;
static modulo(value: DecimalSource, other: DecimalSource): Decimal;
static modular(value: DecimalSource, other: DecimalSource): Decimal;
static cmp(value: DecimalSource, other: DecimalSource): CompareResult;
static cmpabs(value: DecimalSource, other: DecimalSource): CompareResult;
static compare(value: DecimalSource, other: DecimalSource): CompareResult;
Expand Down Expand Up @@ -118,15 +121,16 @@ export default class Decimal {
static sqrt(value: DecimalSource): Decimal;
static cube(value: DecimalSource): Decimal;
static cbrt(value: DecimalSource): Decimal;
static tetrate(value: DecimalSource, height?: number, payload?: DecimalSource): Decimal;
static iteratedexp(value: DecimalSource, height?: number, payload?: Decimal): Decimal;
static iteratedlog(value: DecimalSource, base?: DecimalSource, times?: number): Decimal;
static layeradd10(value: DecimalSource, diff: DecimalSource): Decimal;
static layeradd(value: DecimalSource, diff: number, base?: number): Decimal;
static slog(value: DecimalSource, base?: number): Decimal;
static tetrate(value: DecimalSource, height?: number, payload?: DecimalSource, linear?: boolean): Decimal;
static iteratedexp(value: DecimalSource, height?: number, payload?: Decimal, linear?: boolean): Decimal;
static iteratedlog(value: DecimalSource, base?: DecimalSource, times?: number, linear?: boolean): Decimal;
static layeradd10(value: DecimalSource, diff: DecimalSource, linear?: boolean): Decimal;
static layeradd(value: DecimalSource, diff: number, base?: number, linear?: boolean): Decimal;
static slog(value: DecimalSource, base?: number, linear?: boolean): Decimal;
static lambertw(value: DecimalSource): Decimal;
static ssqrt(value: DecimalSource): Decimal;
static pentate(value: DecimalSource, height?: number, payload?: DecimalSource): Decimal;
static linear_sroot(value: DecimalSource, height: number): Decimal;
static pentate(value: DecimalSource, height?: number, payload?: DecimalSource, linear?: boolean): Decimal;
/**
* If you're willing to spend 'resourcesAvailable' and want to buy something
* with exponentially increasing cost each purchase (start at priceStart,
Expand Down Expand Up @@ -207,6 +211,9 @@ export default class Decimal {
recip(): Decimal;
reciprocal(): Decimal;
reciprocate(): Decimal;
mod(value: DecimalSource): Decimal;
modulo(value: DecimalSource): Decimal;
modular(value: DecimalSource): Decimal;
/**
* -1 for less than value, 0 for equals value, 1 for greater than value
*/
Expand Down Expand Up @@ -264,19 +271,20 @@ export default class Decimal {
sqrt(): Decimal;
cube(): Decimal;
cbrt(): Decimal;
tetrate(height?: number, payload?: DecimalSource): Decimal;
iteratedexp(height?: number, payload?: Decimal): Decimal;
iteratedlog(base?: DecimalSource, times?: number): Decimal;
slog(base?: DecimalSource, iterations?: number): Decimal;
slog_internal(base?: DecimalSource): Decimal;
tetrate(height?: number, payload?: DecimalSource, linear?: boolean): Decimal;
iteratedexp(height?: number, payload?: Decimal, linear?: boolean): Decimal;
iteratedlog(base?: DecimalSource, times?: number, linear?: boolean): Decimal;
slog(base?: DecimalSource, iterations?: number, linear?: boolean): Decimal;
slog_internal(base?: DecimalSource, linear?: boolean): Decimal;
static slog_critical(base: number, height: number): number;
static tetrate_critical(base: number, height: number): number;
static critical_section(base: number, height: number, grid: number[][]): number;
layeradd10(diff: DecimalSource): Decimal;
layeradd(diff: number, base: DecimalSource): Decimal;
static critical_section(base: number, height: number, grid: number[][], linear?: boolean): number;
layeradd10(diff: DecimalSource, linear?: boolean): Decimal;
layeradd(diff: number, base: DecimalSource, linear?: boolean): Decimal;
lambertw(): Decimal;
ssqrt(): Decimal;
pentate(height?: number, payload?: DecimalSource): Decimal;
linear_sroot(degree: number): Decimal;
pentate(height?: number, payload?: DecimalSource, linear?: boolean): Decimal;
sin(): this | Decimal;
cos(): Decimal;
tan(): this | Decimal;
Expand Down
Loading

0 comments on commit 6169647

Please sign in to comment.