Class Decimal

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.

Constructors

Properties

Accessors

Methods

abs absLog10 acos acosh add ascensionPenalty asin asinh atan atanh cbrt ceil clamp clampMax clampMin clone cmp cmp_tolerance cmpabs compare compare_tolerance cos cosh cube div divide divideBy dividedBy egg eq eq_tolerance equals equals_tolerance exp factorial floor format formatGain formatST fromComponents fromComponents_noNormalize fromDecimal fromMantissaExponent fromMantissaExponent_noNormalize fromNumber fromString fromValue gamma greaterThan greaterThanOrEqualTo gt gt_tolerance gte gte_tolerance isFinite isNan iteratedexp iteratedlog lambertw layeradd layeradd10 lessThan lessThanOrEqualTo linear_penta_root linear_sroot ln lngamma log log10 log2 logarithm lt lt_tolerance lte lte_tolerance magnitudeWithDecimalPlaces mantissaWithDecimalPlaces max maxabs min minabs minus mod modular modulo mul multiply neg negate negated neq neq_tolerance normalize notEquals notEquals_tolerance penta_log pentate pLog10 plus pow pow_base pow10 recip reciprocal reciprocate root round scale sgn sin sinh slog slog_internal softcap sqr sqrt ssqrt sub subtract tan tanh tetrate times toExponential toFixed toJSON toNumber toPrecision toRoman toString toStringWithDecimalPlaces trunc valueOf abs absLog10 acos acosh add affordArithmeticSeries affordArithmeticSeries_core affordGeometricSeries affordGeometricSeries_core asin asinh atan atanh cbrt ceil clamp clampMax clampMin clone cmp cmp_tolerance cmpabs compare compare_tolerance cos cosh critical_section cube div divide efficiencyOfPurchase efficiencyOfPurchase_core eq eq_tolerance equals equals_tolerance exp factorial floor format formatGain formatST fromComponents fromComponents_noNormalize fromDecimal fromMantissaExponent fromMantissaExponent_noNormalize fromNumber fromString fromValue fromValue_noAlloc gamma gt gt_tolerance gte gte_tolerance increasingInverse isFinite isNaN iteratedexp iteratedlog lambertw layeradd layeradd10 linear_penta_root linear_sroot ln lngamma log log10 log2 logarithm lt lt_tolerance lte lte_tolerance max maxabs min minabs minus mod modular modulo mul multiply neg negate negated neq neq_tolerance notEquals notEquals_tolerance penta_log pentate pLog10 plus pow pow10 random randomDecimalForTesting randomProb recip reciprocal reciprocate root round scale sgn sign sin sinh slog slog_critical smoothDamp softcap sqr sqrt ssqrt sub subtract sumArithmeticSeries sumArithmeticSeries_core sumGeometricSeries sumGeometricSeries_core tan tanh tetrate tetrate_critical times toRoman trunc

Constructors

Properties

layer: number = 0
mag: number = 0
sign: number = 0
dInf: Decimal = ...

Represents positive infinity.

dLayerMax: Decimal = ...

Represents the largest finite value a Decimal can represent. Approximately 10^^(1.79 * 10^308).

dLayerMin: Decimal = ...

Represents the smallest non-zero value a Decimal can represent. Approximately 1 / (10^^(1.79 * 10^308)).

dLayerSafeMax: Decimal = ...

Represents the largest Decimal where adding 1 to the layer is a safe operation (Decimals larger than this are too big for pow/exp/log to affect, but tetrate/iteratedlog/slog can still affect them). Approximately 10^^(9.007 * 10^15).

dLayerSafeMin: Decimal = ...

Represents the smallest Decimal where adding 1 to the layer is a safe operation. Approximately 1 / (10^^(9.007 * 10^15)).

dNaN: Decimal = ...

Represents a NaN (Not A Number) value.

dNegInf: Decimal = ...

Represents negative infinity.

dNegOne: Decimal = ...

Represents the number -1.

dNumberMax: Decimal = ...

Represents the largest value a JavaScript number can have, which is approximately 1.79 * 10^308.

dNumberMin: Decimal = ...

Represents the smallest value a JavaScript number can have, which is approximately 5 * 10^-324.

dOne: Decimal = ...

Represents the number 1.

dTen: Decimal = ...

Represents the number 10.

dTwo: Decimal = ...

Represents the number 2.

dZero: Decimal = ...

Represents the number 0.

formats: {
    alphabet: {
        config: {
            alphabet: string;
        };
        format(ex: DecimalSource, acc?: number, max?: number, type?: FormatType, start?: DecimalSource, startDouble?: boolean, abbStart?: number): string;
        getAbbreviation(ex: DecimalSource, start?: DecimalSource, startDouble?: boolean, abbStart?: number): string;
    };
    elemental: {
        config: {
            element_lists: string[][];
        };
        abbreviationLength(group: number): number;
        beyondOg(x: number): string;
        format(value: Decimal, acc?: number): string;
        formatElementalPart(abbreviation: string, n: Decimal): string;
        getAbbreviation(group: number, progress: number): string;
        getAbbreviationAndValue(x: Decimal): [string, Decimal];
        getOffset(group: number): number;
    };
    eng: {
        format(ex: DecimalSource, acc?: number): string;
    };
    ev: ((num: DecimalSource, c2?: boolean) => string);
    expMult: ((a: DecimalSource, b: DecimalSource, base?: number) => Decimal);
    format: ((ex: DecimalSource, acc?: number, max?: number, type?: FormatType) => string);
    formatGain: ((amt: DecimalSource, gain: DecimalSource, type?: FormatType, acc?: number, max?: number) => string);
    formatMult: ((ex: DecimalSource, acc?: number) => string);
    formatPercent: ((ex: DecimalSource) => string);
    formatReduction: ((ex: DecimalSource) => string);
    formatST: ((ex: DecimalSource, acc?: number, max?: number, type?: FormatType) => string);
    formatTime: ((ex: DecimalSource, acc?: number, type?: string) => string);
    formatTimeLong: ((ex: DecimalSource, ms?: boolean, acc?: number, max?: number, type?: FormatType) => string);
    inf: {
        format(ex: DecimalSource, acc?: number, max?: number): string;
    };
    layer: {
        layers: string[];
        format(ex: DecimalSource, acc?: number, max?: number): string;
    };
    metric: ((num: DecimalSource, type?:
        | 0
        | 1
        | 2
        | 3) => string);
    mixed_sc: {
        format(ex: DecimalSource, acc?: number, max?: number): string;
    };
    old_sc: {
        format(ex: DecimalSource, acc: number): string;
    };
    omega: {
        config: {
            greek: string;
            infinity: string;
        };
        format(value: DecimalSource): string;
    };
    omega_short: {
        config: {
            greek: string;
            infinity: string;
        };
        format(value: DecimalSource): string;
    };
    standard: {
        tier1(x: number): string;
        tier2(x: number): string;
    };
    toSubscript: ((value: number) => string);
    toSuperscript: ((value: number) => string);
}

Type declaration

  • alphabet: {
        config: {
            alphabet: string;
        };
        format(ex: DecimalSource, acc?: number, max?: number, type?: FormatType, start?: DecimalSource, startDouble?: boolean, abbStart?: number): string;
        getAbbreviation(ex: DecimalSource, start?: DecimalSource, startDouble?: boolean, abbStart?: number): string;
    }

    Alphabet format

    • config: {
          alphabet: string;
      }
      • alphabet: string
    • format:function
      • Format the value into alphabet format (a, b, c, ..., z, aa, ab, ac, ... aaa, aab, ... aaaa, ... aaaaaaaaaaaaaaa, ... aaaaaaaaaaaaaaa(2), aaaaaaaaaaaaaaa(3), ...) Basically base 26 for the exponential part / 3 Work in progress

        Parameters

        • ex: DecimalSource

          The value to format

        • acc: number = 2

          The accuracy

        • max: number = 9

          The maximum value before switching to an abbreviation

        • type: FormatType = "mixed_sc"

          The type of format to use

        • start: DecimalSource = ...

          The starting value. Defaults to 1e15, or 1 quadrillion.

        • startDouble: boolean = false

          Whether to start at aa instead of a. Defaults to false.

        • OptionalabbStart: number

          The starting value for abbreviations. Defaults to 9.

        Returns string

        • The formatted value
    • getAbbreviation:function
      • Get the abbreviation for a number

        Parameters

        • ex: DecimalSource

          The value to get the abbreviation for

        • start: DecimalSource = ...

          The starting value

        • startDouble: boolean = false

          Whether to start at aa instead of a

        • abbStart: number = 9

          The starting value for abbreviations

        Returns string

        • The abbreviation
  • elemental: {
        config: {
            element_lists: string[][];
        };
        abbreviationLength(group: number): number;
        beyondOg(x: number): string;
        format(value: Decimal, acc?: number): string;
        formatElementalPart(abbreviation: string, n: Decimal): string;
        getAbbreviation(group: number, progress: number): string;
        getAbbreviationAndValue(x: Decimal): [string, Decimal];
        getOffset(group: number): number;
    }
    • config: {
          element_lists: string[][];
      }
      • element_lists: string[][]

        The list of elements

    • abbreviationLength:function
      • Parameters

        • group: number

        Returns number

    • beyondOg:function
      • Parameters

        • x: number

        Returns string

    • format:function
    • formatElementalPart:function
      • Parameters

        Returns string

    • getAbbreviation:function
      • Parameters

        • group: number
        • progress: number

        Returns string

    • getAbbreviationAndValue:function
    • getOffset:function
      • Parameters

        • group: number

        Returns number

  • eng: {
        format(ex: DecimalSource, acc?: number): string;
    }

    Engineering format

    • format:function
      • Format the value into engineering format

        Parameters

        • ex: DecimalSource

          The value to format

        • acc: number = 2

          The accuracy

        Returns string

        • The formatted value
        console.log(FORMATS.eng.format(1e20, 2)); // 100.00e18
        
  • ev: ((num: DecimalSource, c2?: boolean) => string)
      • (num, c2?): string
      • Format the value into eV (includes metric prefixes)

        Parameters

        • num: DecimalSource

          The value to format

        • c2: boolean = false

          Whether to include /c^2

        Returns string

        The formatted value

        Use metric instead

  • expMult: ((a: DecimalSource, b: DecimalSource, base?: number) => Decimal)
      • (a, b, base?): Decimal
      • Exponential multiplier

        Parameters

        Returns Decimal

        • The value after being exponentiated
  • format: ((ex: DecimalSource, acc?: number, max?: number, type?: FormatType) => string)
      • (ex, acc?, max?, type?): string
      • Format the value into a specific format type

        Parameters

        • ex: DecimalSource

          The value to format

        • acc: number = 2

          The desired accuracy (number of significant figures), defaults to 2.

        • max: number = 9

          The maximum number of decimal places to display, defaults to 9.

        • type: FormatType = "mixed_sc"

          The type of format to use (default "mixed_sc")

        Returns string

        • The formatted value
  • formatGain: ((amt: DecimalSource, gain: DecimalSource, type?: FormatType, acc?: number, max?: number) => string)
      • (amt, gain, type?, acc?, max?): string
      • Format the gain

        Parameters

        Returns string

        • The formatted gain
        console.log(formatGain(1e20, 1e10)); // (+1.00e10/sec)
        console.log(formatGain(1e200, 1e210)); // (+10.00 OoMs/sec)
  • formatMult: ((ex: DecimalSource, acc?: number) => string)
      • (ex, acc?): string
      • Format the multiplier

        Parameters

        • ex: DecimalSource

          The value to format

        • acc: number = 2

          The accuracy

        Returns string

        • The formatted multiplier
  • formatPercent: ((ex: DecimalSource) => string)
      • (ex): string
      • Format the percent

        Parameters

        Returns string

        • The formatted percent
  • formatReduction: ((ex: DecimalSource) => string)
      • (ex): string
      • Format the reduction

        Parameters

        Returns string

        • The formatted reduction
  • formatST: ((ex: DecimalSource, acc?: number, max?: number, type?: FormatType) => string)
      • (ex, acc?, max?, type?): string
      • Format the value into standard (letter abbv) format

        Parameters

        Returns string

        Use format instead (with the type "st")

  • formatTime: ((ex: DecimalSource, acc?: number, type?: string) => string)
      • (ex, acc?, type?): string
      • Format the time

        Parameters

        • ex: DecimalSource

          The value to format (in seconds)

        • acc: number = 2

          The accuracy

        • type: string = "s"

          The type

        Returns string

        • The formatted time
  • formatTimeLong: ((ex: DecimalSource, ms?: boolean, acc?: number, max?: number, type?: FormatType) => string)
      • (ex, ms?, acc?, max?, type?): string
      • Format the time long

        Parameters

        • ex: DecimalSource

          The value to format (in seconds)

        • ms: boolean = false

          Whether to include milliseconds

        • acc: number = 0

          The accuracy

        • max: number = 9

          The maximum value

        • type: FormatType = "mixed_sc"

          The type

        Returns string

        • The formatted time
  • inf: {
        format(ex: DecimalSource, acc?: number, max?: number): string;
    }

    Infinity format

    • format:function
  • layer: {
        layers: string[];
        format(ex: DecimalSource, acc?: number, max?: number): string;
    }

    Layer format

    • layers: string[]
    • format:function
  • metric: ((num: DecimalSource, type?:
        | 0
        | 1
        | 2
        | 3) => string)
      • (num, type?): string
      • Converts a number to a metric representation based on the specified type.

        Parameters

        • num: DecimalSource

          The number to convert.

        • type:
              | 0
              | 1
              | 2
              | 3 = 0

          The type of metric representation to return.

          • 0: Returns the number with the metric abbreviation (e.g., "1.23 K").
          • 1: Returns only the metric abbreviation (e.g., "K").
          • 2: Returns the number divided by the metric value (e.g., "1.23").
          • 3: Returns the alternative name of the metric abbreviation (e.g., "Kilo").

        Returns string

        The metric representation of the number. If the number is greater than the highest metric value, the function returns the highest metric abbreviation.

        metric(1234, 0); // Returns "1.23 K"
        metric(1234, 1); // Returns "K"
        metric(1234, 2); // Returns "1.23"
        metric(1234, 3); // Returns "Kilo"
  • mixed_sc: {
        format(ex: DecimalSource, acc?: number, max?: number): string;
    }

    Mixed scientific format

    • format:function
      • Format the value into mixed scientific format (standard or scientific depending on the value)

        Parameters

        • ex: DecimalSource

          The value to format

        • Optionalacc: number

          The accuracy

        • max: number = 9

          The maximum value

        Returns string

        • The formatted value
        console.log(FORMATS.mixed_sc.format(1e20, 2, 9)); // 100.00 Qt
        console.log(FORMATS.mixed_sc.format(1e400, 2, 303)); // 1.00e400
  • old_sc: {
        format(ex: DecimalSource, acc: number): string;
    }

    Old scientific format

    • format:function
      • Format the value into old scientific format

        Parameters

        Returns string

        • The formatted value
  • omega: {
        config: {
            greek: string;
            infinity: string;
        };
        format(value: DecimalSource): string;
    }

    Omega format

    • config: {
          greek: string;
          infinity: string;
      }
      • greek: string
      • infinity: string
    • format:function
      • Format the value into omega format

        Parameters

        Returns string

        • The formatted value
  • omega_short: {
        config: {
            greek: string;
            infinity: string;
        };
        format(value: DecimalSource): string;
    }

    Short omega format

    • config: {
          greek: string;
          infinity: string;
      }
      • greek: string
      • infinity: string
    • format:function
      • Format the value into short omega format

        Parameters

        Returns string

        • The formatted value
  • standard: {
        tier1(x: number): string;
        tier2(x: number): string;
    }

    Standard (letter abbv) format

    • tier1:function
      • Gets the letter abbreviation for a number (e.g. 1 -> K) (0-1e3000)

        Parameters

        • x: number

          The number to get the letter abbreviation for

        Returns string

        • The letter abbreviation
    • tier2:function
      • Gets the tier 2 letter abbreviation for a number (e.g. 1 -> Mi) (1e3000+)

        Parameters

        • x: number

          The number to get the letter abbreviation for

        Returns string

        • The letter abbreviation
  • toSubscript: ((value: number) => string)
      • (value): string
      • Convert a number to a subscript

        Parameters

        • value: number

          The value to convert

        Returns string

        • The value in subscript
  • toSuperscript: ((value: number) => string)
      • (value): string
      • Convert a number to a superscript

        Parameters

        • value: number

          The value to convert

        Returns string

        • The value in superscript

Accessors

  • get e(): number
  • Returns number

  • set e(value): void
  • Parameters

    • value: number

    Returns void

  • get exponent(): number
  • Returns number

  • set exponent(value): void
  • Parameters

    • value: number

    Returns void

  • get m(): number
  • Returns number

  • set m(value): void
  • Parameters

    • value: number

    Returns void

  • get mantissa(): number
  • Returns number

  • set mantissa(value): void
  • Parameters

    • value: number

    Returns void

  • get s(): number
  • Returns number

  • set s(value): void
  • Parameters

    • value: number

    Returns void

Methods

  • Absolute value function: returns 'this' if 'this' >= 0, returns the negative of 'this' if this < 0.

    Returns Decimal

  • Cube root: finds the Decimal X such that X^3 equals 'this'. Equivalent to X^(1/3).

    Returns Decimal

  • "Rounds" the Decimal it's called on to the nearest integer that's greater than or equal to it.

    Returns Decimal

  • A combination of minimum and maximum: the value returned by clamp is normally 'this', but it won't go below 'min' and it won't go above 'max'. Therefore, if 'this' < 'min', then 'min' is returned, and if 'this' > 'max', then 'max' is returned.

    Parameters

    Returns Decimal

  • Creates a clone of the Decimal instance.

    Returns this

    A EClone instance that is a clone of the original.

  • Returns 1 if 'this' is greater than 'value', returns -1 if 'this' is less than 'value', returns 0 if 'this' is equal to 'value'. However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns CompareResult

  • Compares the absolute values of this and value. Returns 1 if |'this'| > |'value'|, returns -1 if |'this'| < |'value'|, returns 0 if |'this'| == |'value'|.

    Parameters

    Returns CompareResult

  • Returns 1 if 'this' is greater than 'value', returns -1 if 'this' is less than 'value', returns 0 if 'this' is equal to 'value'. However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns CompareResult

  • The cosine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi.

    Returns Decimal

  • The Decimal equivalent of ==. Returns true if 'this' and 'value' have equal values.

    Parameters

    Returns boolean

  • Tests whether two Decimals are approximately equal, up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • Returns true if 'this' and 'value' have equal values.

    Parameters

    Returns boolean

  • Tests whether two Decimals are approximately equal, up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • For positive integers, X factorial (written as X!) equals X * (X - 1) * (X - 2) *... * 3 * 2 * 1. 0! equals 1. This can be extended to real numbers (except for negative integers) via the gamma function, which is what this function does.

    Returns Decimal

  • "Rounds" the Decimal it's called on to the nearest integer that's less than or equal to it.

    Returns Decimal

  • Formats the Decimal instance with a specified accuracy and maximum decimal places.

    Parameters

    • Optionalacc: number = 2

      The desired accuracy (number of significant figures), defaults to 2.

    • Optionalmax: number = 9

      The maximum number of decimal places to display, defaults to 9.

    • Optionaltype: FormatType = "mixed_sc"

      The type of format, defaults to "mixed_sc".

    Returns string

    A string representing the formatted Decimal value.

  • Formats the gain rate using the Decimal instance.

    Parameters

    • gain: DecimalSource

      The gain value to compare

    • Optionaltype: FormatType = "mixed_sc"

      The type of format (default mixed scientific)

    • Optionalacc: number

      The desired accuracy (number of significant figures).

    • Optionalmax: number

      The maximum number of decimal places to display.

    Returns string

    A string representing the formatted gain

    const currency = new Decimal(100);
    const currencyGain = new Decimal(12);
    const formatted = currency.formats.formatGain(currencyGain);
    console.log(formatted); // should return "(+12/sec)"
  • Formats the Decimal instance in standard leter notation with a specified accuracy and maximum decimal places.

    Parameters

    • Optionalacc: number = 2

      The desired accuracy (number of significant figures).

    • Optionalmax: number = 9

      The maximum number of decimal places to display.

    • Optionaltype: FormatType = "st"

      The type of format (default standard)

    Returns string

    A string representing the formatted Decimal value.

  • Turns the given components into a valid Decimal.

    Note: this function mutates the Decimal it is called on.

    Parameters

    • sign: number
    • layer: number
    • mag: number

    Returns this

  • Turns the given components into a Decimal, but not necessarily a valid one (it's only valid if the components would already create a valid Decimal without normalization). Users of this library should not use this function.

    Note: this function mutates the Decimal it is called on.

    Parameters

    • sign: number
    • layer: number
    • mag: number

    Returns this

  • Turns the Decimal that this function is called on into a deep copy of the provided value.

    Note: this function mutates the Decimal it is called on.

    Parameters

    Returns this

  • Turns the mantissa and exponent into a valid Decimal with value mantissa * 10^exponent.

    Note: this function mutates the Decimal it is called on.

    Parameters

    • mantissa: number
    • exponent: number

    Returns this

  • Turns the mantissa and exponent into a Decimal, but not necessarily a valid one. Users of this library should not use this function.

    Note: this function mutates the Decimal it is called on.

    Parameters

    • mantissa: number
    • exponent: number

    Returns this

  • Converts a floating-point number into a Decimal.

    Note: this function mutates the Decimal it is called on.

    Parameters

    • value: number

    Returns this

  • Converts a string into a Decimal.

    If linearhyper4 is true, then strings like "10^^8.5" will use the linear approximation of tetration even for bases <= 10.

    Note: this function mutates the Decimal it is called on.

    Parameters

    • value: string
    • linearhyper4: boolean = false

    Returns this

  • The function used by new Decimal() to create a new Decimal. Accepts a DecimalSource: uses fromNumber if given a number, uses fromString if given a string, and uses fromDecimal if given a Decimal.

    Note: this function mutates the Decimal it is called on.

    Parameters

    Returns this

  • The gamma function extends the idea of factorials to non-whole numbers using some calculus. Gamma(x) is defined as the integral of t^(x-1) * e^-t dt from t = 0 to t = infinity, and gamma(x) = (x - 1)! for nonnegative integer x, so the factorial for non-whole numbers is defined using the gamma function.

    Returns Decimal

  • The Decimal equivalent of >. Returns true if 'this' is greater than 'value'.

    Parameters

    Returns boolean

  • Returns true if 'this' is greater than 'value'. However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • The Decimal equivalent of >=. Returns true if 'this' is greater than or equal to 'value'.

    Parameters

    Returns boolean

  • Returns true if 'this' is greater than or equal to 'value'. However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • Returns true if the Decimal is finite (by Decimal standards, not by floating point standards - a humongous Decimal like 10^^10^100 is still finite!)

    Returns boolean

  • Returns true if the Decimal is an NaN value.

    Returns boolean

  • Iterated exponentiation, the result of exping 'payload' to base 'this' 'height' times. https://andydude.github.io/tetration/archives/tetration2/ident.html

    Works with negative and positive real heights. Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    Identical to tetrate.

    Parameters

    • height: number = 2
    • payload: Decimal = ...
    • linear: boolean = false

    Returns Decimal

  • iterated log/repeated log: The result of applying log(base) 'times' times in a row. Approximately equal to subtracting 'times' from the number's slog representation. Equivalent to tetrating to a negative height.

    Works with negative and positive real heights. Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    Parameters

    Returns Decimal

  • The Lambert W function, also called the omega function or product logarithm, is the solution W(x) === x*e^x. https://en.wikipedia.org/wiki/Lambert_W_function

    This is a multi-valued function in the complex plane, but only two branches matter for real numbers: the "principal branch" W0, and the "non-principal branch" W_-1. W_0 works for any number >= -1/e, but W_-1 only works for nonpositive numbers >= -1/e. The "principal" parameter, which is true by default, decides which branch we're looking for: W_0 is used if principal is true, W_-1 is used if principal is false.

    Parameters

    • principal: boolean = true

    Returns Decimal

  • layeradd: like adding 'diff' to the number's slog(base) representation. Very similar to tetrate base 'base' and iterated log base 'base'.

    Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    Parameters

    Returns Decimal

  • Adds/removes layers from a Decimal, even fractional layers (e.g. its slog10 representation). Very similar to tetrate base 10 and iterated log base 10.

    Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    Parameters

    Returns Decimal

  • Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'this'?

    Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots.

    Parameters

    • degree: number

    Returns Decimal

  • Super-root, one of tetration's inverses - what number, tetrated to height 'degree', equals 'this'? https://en.wikipedia.org/wiki/Tetration#Super-root

    Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. This only matters for non-integer degrees.

    Parameters

    • degree: number

    Returns Decimal

  • Base-e logarithm, also known as the "natural" logarithm: returns the Decimal X such that e^X = 'this'.

    Returns Decimal

  • Logarithms are one of the inverses of exponentiation: this function finds the Decimal X such that base^X = 'this'.

    Parameters

    Returns Decimal

  • Base-10 logarithm: returns the Decimal X such that 10^X = 'this'. For numbers above layer 0, this is equivalent to subtracting 1 from layer and normalizing.

    Returns Decimal

  • Logarithms are one of the inverses of exponentiation: this function finds the Decimal X such that base^X = 'this'.

    Parameters

    Returns Decimal

  • The Decimal equivalent of <. Returns true if 'this' is less than 'value'.

    Parameters

    Returns boolean

  • Returns true if 'this' is less than 'value'. However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • The Decimal equivalent of <=. Returns true if 'this' is less than or equal to 'value'.

    Parameters

    Returns boolean

  • Returns true if 'this' is less than or equal to 'value'. However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • Parameters

    • places: number

    Returns number

  • Parameters

    • places: number

    Returns number

  • Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers.

    Parameters

    Returns Decimal

  • Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers.

    Parameters

    Returns Decimal

  • Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers.

    Parameters

    Returns Decimal

  • Negates the Decimal it's called on: in other words, when given X, returns -X.

    Returns Decimal

  • Negates the Decimal it's called on: in other words, when given X, returns -X.

    Returns Decimal

  • Negates the Decimal it's called on: in other words, when given X, returns -X.

    Returns Decimal

  • The Decimal equivalent of !=. Returns true if 'this' and 'value' do not have equal values.

    Parameters

    Returns boolean

  • Tests whether two Decimals are not approximately equal, up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • Turns the Decimal into a valid Decimal. This function is meant for internal purposes - users of this library should not need to use normalize.

    Note: this function mutates the Decimal it is called on.

    Returns this

  • Returns true if 'this' and 'value' do not have equal values.

    Parameters

    Returns boolean

  • Tests whether two Decimals are not approximately equal, up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'this'.

    Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function.

    Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth.

    Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation.

    Parameters

    • base: DecimalSource = 10
    • iterations: number = 100
    • linear: boolean = false

    Returns Decimal

  • Pentation/pentate: The result of tetrating 'height' times in a row. An absurdly strong operator - Decimal.pentate(2, 4.28) and Decimal.pentate(10, 2.37) are already too huge for break_eternity.js! https://en.wikipedia.org/wiki/Pentation

    Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation.

    Parameters

    • height: number = 2
    • payload: DecimalSource = ...
    • linear: boolean = false

    Returns Decimal

  • "Positive log10": Returns the base-10 logarithm of nonnegative Decimals, but returns 0 for negative Decimals.

    Returns Decimal

  • Exponentiation: Returns the result of 'this' ^ 'value' (often written as 'this' ** 'value' in programming languages).

    Parameters

    Returns Decimal

  • Exponentiation: Returns the result of 'value' ^ 'this' (often written as 'value' ** 'this' in programming languages).

    Parameters

    Returns Decimal

  • Raises 10 to the power of 'this', i.e. (10^'this'). For positive numbers above 1, this is equivalent to adding 1 to layer and normalizing.

    Returns Decimal

  • Roots are one of the inverses of exponentiation: this function finds the Decimal X such that X ^ 'value' = 'this'. Equivalent to 'this' ^ (1 / 'value'), which is written here as this.pow(value.recip()).

    Parameters

    Returns Decimal

  • Scales a currency value using a specified scaling function.

    Parameters

    • s: DecimalSource

      The value at which scaling starts.

    • p: DecimalSource

      The scaling factor.

    • mode: string | number

      The scaling mode. Use "pow" for power scaling or "exp" for exponential scaling.

    • Optionalrev: boolean = false

      Whether to reverse the scaling operation (unscaling).

    Returns this

    • The scaled currency value.
  • Returns the sign of the Decimal it's called on. (Though, since sign is a public data member of Decimal, you might as well just call .sign instead of .sgn())

    Returns number

  • The sine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi.

    Returns Decimal

  • Super-logarithm, one of tetration's inverses, tells you what size power tower you'd have to tetrate 'base' to to get 'this'. https://en.wikipedia.org/wiki/Super-logarithm

    By definition, will never be higher than 1.8e308 in break_eternity.js, since a power tower 1.8e308 numbers tall is the largest representable number.

    Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming tetration as the ground truth.

    Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    Parameters

    • base: DecimalSource = 10
    • iterations: number = 100
    • linear: boolean = false

    Returns Decimal

  • Applies a soft cap to a DecimalClone value using a specified soft cap function.

    Parameters

    • start: DecimalSource

      The value at which the soft cap starts.

    • power: number

      The power or factor used in the soft cap calculation.

    • mode: string

      The soft cap mode. Use "pow" for power soft cap, "mul" for multiplication soft cap, or "exp" for exponential soft cap.

    Returns this

    • The DecimalClone value after applying the soft cap.
  • Squaring a number means multiplying it by itself, a.k.a. raising it to the second power.

    Returns Decimal

  • Square root: finds the Decimal X such that X * X, a.k.a X^2, equals 'this'. Equivalent to X^(1/2).

    Returns Decimal

  • The tangent function, equal to sine divided by cosine. Behaves periodically with period pi.

    Returns Decimal

  • Tetration: The result of exponentiating 'this' to 'this' 'height' times in a row. https://en.wikipedia.org/wiki/Tetration

    If payload != 1, then this is 'iterated exponentiation', the result of exping 'payload' to base 'this' 'height' times. https://andydude.github.io/tetration/archives/tetration2/ident.html

    Works with negative and positive real heights. Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    Parameters

    • height: number = 2
    • payload: DecimalSource = ...
    • linear: boolean = false

    Returns Decimal

  • Parameters

    • places: number

    Returns string

  • Parameters

    • places: number

    Returns string

  • Returns the numeric value of the Decimal it's called on. Will return Infinity (or -Infinity for negatives) for Decimals that are larger than Number.MAX_VALUE.

    Returns number

  • Parameters

    • places: number

    Returns string

  • Converts the Decimal instance to a Roman numeral representation.

    Parameters

    • Optionalmax: DecimalSource = 5000

      Max before it returns the original

    Returns string | Decimal

    A string representing the Roman numeral equivalent of the Decimal value, or the original Decimal instance if it is greater than or equal to 5000 or less than 1.

  • Returns a string representation of the Decimal it's called on. This string is written as a plain number for most layer 0 numbers, in scientific notation for layer 1 numbers (and layer 0 numbers below 1e-6), in "ee...X" form for numbers from layers 2 to 5, and in (e^N)X form for layer > 5.

    Returns string

  • Parameters

    • places: number

    Returns string

  • Extracts the integer part of the Decimal and returns it. Behaves like floor on positive numbers, but behaves like ceiling on negative numbers.

    Returns Decimal

  • Absolute value function: returns 'value' if 'value' >= 0, returns the negative of 'value' if 'value' < 0.

    Parameters

    Returns Decimal

  • If you're willing to spend 'resourcesAvailable' and want to buy something with additively increasing cost each purchase (start at priceStart, add by priceAdd, already own currentOwned), how much of it can you buy?

    Parameters

    Returns Decimal

  • If you're willing to spend 'resourcesAvailable' and want to buy something with exponentially increasing cost each purchase (start at priceStart, multiply by priceRatio, already own currentOwned), how much of it can you buy? Adapted from Trimps source code.

    Parameters

    Returns Decimal

  • A combination of minimum and maximum: the value returned by clamp is normally 'value', but it won't go below 'min' and it won't go above 'max'. Therefore, if 'value' < 'min', then 'min' is returned, and if 'value' > 'max', then 'max' is returned.

    Parameters

    Returns Decimal

  • Creates a clone of the Decimal instance. Helps with a webpack(?) bug

    Parameters

    Returns Decimal

    • The cloned number

    Decimal.normalizeFromComponents

  • Returns 1 if 'value' is greater than 'other', returns -1 if 'value' is less than 'other', returns 0 if 'value' is equal to 'other'. However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns CompareResult

  • Returns 1 if 'value' is greater than 'other', returns -1 if 'value' is less than 'other', returns 0 if 'value' is equal to 'other'. However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns CompareResult

  • The cosine function, one of the main two trigonometric functions. Behaves periodically with period 2*pi.

    Parameters

    Returns Decimal

  • Parameters

    • base: number
    • height: number
    • grid: number[][]
    • linear: boolean = false

    Returns number

  • The Decimal equivalent of ==. Returns true if 'value' and 'other' have equal values.

    Parameters

    Returns boolean

  • Tests whether two Decimals are approximately equal, up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • Tests whether two Decimals are approximately equal, up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • For positive integers, X factorial (written as X!) equals X * (X - 1) * (X - 2) *... * 3 * 2 * 1. 0! equals 1. This can be extended to real numbers (except for negative integers) via the gamma function, which is what this function does.

    Parameters

    Returns Decimal

  • Formats the Decimal instance with a specified accuracy and maximum decimal places.

    Parameters

    • e: DecimalSource

      The Decimal instance to format.

    • Optionalacc: number = 2

      The desired accuracy (number of significant figures), defaults to 2.

    • Optionalmax: number = 9

      The maximum number of decimal places to display, defaults to 9.

    • Optionaltype: FormatType = "mixed_sc"

      The type of format, defaults to "mixed_sc".

    Returns string

    A string representing the formatted Decimal value.

  • Turns the given components into a valid Decimal.

    Parameters

    • sign: number
    • layer: number
    • mag: number

    Returns Decimal

  • Turns the given components into a Decimal, but not necessarily a valid one (it's only valid if the components would already create a valid Decimal without normalization). Users of this library should not use this function.

    Parameters

    • sign: number
    • layer: number
    • mag: number

    Returns Decimal

  • Turns the mantissa and exponent into a valid Decimal with value mantissa * 10^exponent.

    Parameters

    • mantissa: number
    • exponent: number

    Returns Decimal

  • Turns the mantissa and exponent into a Decimal, but not necessarily a valid one. Users of this library should not use this function.

    Parameters

    • mantissa: number
    • exponent: number

    Returns Decimal

  • Converts a floating-point number into a Decimal.

    Parameters

    • value: number

    Returns Decimal

  • Converts a string into a Decimal.

    If linearhyper4 is true, then strings like "10^^8.5" will use the linear approximation of tetration even for bases <= 10.

    Parameters

    • value: string
    • linearhyper4: boolean = false

    Returns Decimal

  • The function used by new Decimal() to create a new Decimal. Accepts a DecimalSource: uses fromNumber if given a number, uses fromString if given a string, and uses fromDecimal if given a Decimal.

    Parameters

    Returns Decimal

  • Converts a DecimalSource to a Decimal, without constructing a new Decimal if the provided value is already a Decimal.

    As the return value could be the provided value itself, this function returns a read-only Decimal to prevent accidental mutations of the value. Use new Decimal(value) to explicitly create a writeable copy if mutation is required.

    Parameters

    Returns Readonly<Decimal>

  • The gamma function extends the idea of factorials to non-whole numbers using some calculus. Gamma(x) is defined as the integral of t^(x-1) * e^-t dt from t = 0 to t = infinity, and gamma(x) = (x - 1)! for nonnegative integer x, so the factorial for non-whole numbers is defined using the gamma function.

    Parameters

    Returns Decimal

  • The Decimal equivalent of >. Returns true if 'value' is greater than 'other'.

    Parameters

    Returns boolean

  • Returns true if 'value' is greater than 'other'. However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • The Decimal equivalent of >=. Returns true if 'value' is greater than or equal to 'other'.

    Parameters

    Returns boolean

  • Returns true if 'value' is greater than or equal to 'other'. However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • This function takes a Decimal => Decimal function as its argument (or DecimalSource => Decimal, that's fine too), and it returns a DecimalSource => Decimal function that's an inverse of the first one, which uses binary search to find its target. The resulting function will call the original many times, so it may be noticably slower than the original.

    This function is only intended to be used on continuous, strictly increasing (or, using the decreasing parameter, strictly decreasing) functions. Its resulting function may output erroneous results if the original function was not strictly increasing. If the function is increasing but not strictly increasing, the inverse will, in ranges where the original function is constant, try to return the value closest to 0 out of the multiple correct values. If the function is not continuous, the inverse should return the correct answer in cases where the given value is returned by some input to the original function, but it will return an erroneous result otherwise (the correct result would be to return NaN, but checking to ensure continuity is not implemented)

    Parameters

    • func: ((value: DecimalSource) => Decimal) | ((value: Decimal) => Decimal)

      The Decimal => Decimal function to create an inverse function of.

    • decreasing: boolean = false

      This parameter is false by default. If this parameter is true, the original function should be strictly decreasing instead of strictly increasing.

    • iterations: number = 120

      The amount of iterations that the inverse function runs before it gives up and returns whatever value it's found thus far. Default is 120, which should be enough to always be as precise as floating point allows.

    • minX: DecimalSource = ...

      The original function is assumed to have this value as the lowest value in its domain. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not.

    • maxX: DecimalSource = Decimal.dLayerMax

      The original function is assumed to have this value as the highest value in its domain. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not.

    • minY: DecimalSource = ...

      If the input to the inverse function is below this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax.neg() by default, which means all negative finite values are allowed but infinity is not.

    • maxY: DecimalSource = Decimal.dLayerMax

      If the input to the inverse function is above this value, the inverse function assumes the input is not in the range and returns NaN. Is Decimal.dLayerMax by default, which means all positive finite values are allowed but infinity is not.

    Returns ((value: DecimalSource) => Decimal)

  • Returns true if the given value is finite (by Decimal standards, not by floating point standards - a humongous Decimal like 10^^10^100 is still finite!)

    Parameters

    Returns boolean

  • Returns true if the given value is an NaN value.

    Parameters

    Returns boolean

  • Iterated exponentiation, the result of exping 'payload' to base 'value' 'height' times. https://andydude.github.io/tetration/archives/tetration2/ident.html

    Works with negative and positive real heights. Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    Identical to tetrate.

    Parameters

    Returns Decimal

  • iterated log/repeated log: The result of applying log(base) 'times' times in a row. Approximately equal to subtracting 'times' from the number's slog representation. Equivalent to tetrating to a negative height.

    Works with negative and positive real heights. Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    Parameters

    Returns Decimal

  • The Lambert W function, also called the omega function or product logarithm, is the solution W(x) === x*e^x. https://en.wikipedia.org/wiki/Lambert_W_function

    This is a multi-valued function in the complex plane, but only two branches matter for real numbers: the "principal branch" W0, and the "non-principal branch" W_-1. W_0 works for any number >= -1/e, but W_-1 only works for negative numbers >= -1/e. The "principal" parameter, which is true by default, decides which branch we're looking for: W_0 is used if principal is true, W_-1 is used if principal is false.

    Parameters

    Returns Decimal

  • layeradd: like adding 'diff' to the number's slog(base) representation. Very similar to tetrate base 'base' and iterated log base 'base'.

    Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    Parameters

    Returns Decimal

  • Adds/removes layers from a Decimal, even fractional layers (e.g. its slog10 representation). Very similar to tetrate base 10 and iterated log base 10.

    Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    Parameters

    Returns Decimal

  • Penta-root, one of pentation's inverses - what number, pentated to height 'degree', equals 'value'?

    Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots.

    Parameters

    Returns Decimal

  • Super-root, one of tetration's inverses - what number, tetrated to height 'degree', equals 'value'? https://en.wikipedia.org/wiki/Tetration#Super-root

    Only works with the linear approximation of tetration, as starting with analytic and then switching to linear would result in inconsistent behavior for super-roots. This only matters for non-integer degrees.

    Parameters

    Returns Decimal

  • Base-10 logarithm: returns the Decimal X such that 10^X = 'value'. For numbers above layer 0, this is equivalent to subtracting 1 from layer and normalizing.

    Parameters

    Returns Decimal

  • The Decimal equivalent of <. Returns true if 'value' is less than 'other'.

    Parameters

    Returns boolean

  • Returns true if 'value' is less than 'other'. However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • The Decimal equivalent of <=. Returns true if 'value' is less than or equal to 'other'.

    Parameters

    Returns boolean

  • Returns true if 'value' is less than or equal to 'other'. However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers.

    Parameters

    Returns Decimal

  • Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers.

    Parameters

    Returns Decimal

  • Returns the remainder of 'this' divided by 'value': for example, 5 mod 2 = 1, because the remainder of 5 / 2 is 1. Uses the "truncated division" modulo, which is the same as JavaScript's native modulo operator (%)... unless 'floored' is true, in which case it uses the "floored" modulo, which is closer to how modulo works in number theory. These two forms of modulo are the same when only positive numbers are involved, but differ in how they work with negative numbers.

    Parameters

    Returns Decimal

  • The Decimal equivalent of !=. Returns true if 'value' and 'other' do not have equal values.

    Parameters

    Returns boolean

  • Tests whether two Decimals are not approximately equal, up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • Returns true if 'value' and 'other' do not have equal values.

    Parameters

    Returns boolean

  • Tests whether two Decimals are not approximately equal, up to a certain tolerance. Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments. For example, if you put in 1e-9, then any number closer to the larger number than (larger number)*1e-9 will be considered equal.

    Parameters

    Returns boolean

  • Penta-logarithm, one of pentation's inverses, tells you what height you'd have to pentate 'base' to to get 'value'.

    Grows incredibly slowly. For bases above 2, you won't be seeing a result greater than 5 out of this function.

    Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming pentation as the ground truth.

    Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation.

    Parameters

    Returns Decimal

  • Pentation/pentate: The result of tetrating 'height' times in a row. An absurdly strong operator - Decimal.pentate(2, 4.28) and Decimal.pentate(10, 2.37) are already too huge for break_eternity.js! https://en.wikipedia.org/wiki/Pentation

    Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    For non-whole pentation heights, the linear approximation of pentation is always used, as there is no defined analytic approximation of pentation.

    Parameters

    Returns Decimal

  • "Positive log10": Returns the base-10 logarithm of nonnegative Decimals, but returns 0 for negative Decimals.

    Parameters

    Returns Decimal

  • Raises 10 to the power of 'value', i.e. (10^'value'). For positive numbers above 1, this is equivalent to adding 1 to the value's layer and normalizing.

    Parameters

    Returns Decimal

  • Returns a random Decimal value between the specified minimum and maximum values. This suffers from floating point errors if you want to generate a random number close to either the minimum or the maximum.

    Parameters

    Returns Decimal

    A random Decimal value between the minimum and maximum values.

  • Returns a random boolean value based on the specified probability.

    Parameters

    • rng: DecimalSource

      The probability of returning true. Must be between 0 and 1.

    Returns boolean

    A boolean value based on the probability.

    randomProb(0.5); // 50% chance of returning true
    randomProb(0.25); // 25% chance of returning true
    randomProb(Decimal.dOne.div(1000)); // 1 in 1000 chance of returning true
    // Anything less than ~1e-16 will always return false due to floating point errors
  • Roots are one of the inverses of exponentiation: this function finds the Decimal X such that X ^ 'other' = 'value'. Equivalent to 'value' ^ (1 / 'other'), which is written here as value.pow(other.recip()).

    Parameters

    Returns Decimal

  • Returns the sign of the given value.

    Parameters

    Returns number

  • Returns the sign of the given value.

    Parameters

    Returns number

  • Super-logarithm, one of tetration's inverses, tells you what size power tower you'd have to tetrate 'base' to to get 'value'. https://en.wikipedia.org/wiki/Super-logarithm

    By definition, will never be higher than 1.8e308 in break_eternity.js, since a power tower 1.8e308 numbers tall is the largest representable number.

    Accepts a number of iterations (default is 100), and use binary search to, after making an initial guess, hone in on the true value, assuming tetration as the ground truth.

    Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    Parameters

    Returns Decimal

  • Parameters

    • base: number
    • height: number

    Returns number

  • Smoothly interpolates between the current value and the target value over time using a smoothing factor and deltaTime.

    Parameters

    • current: DecimalSource

      The current value to interpolate from.

    • target: DecimalSource

      The target value to interpolate towards.

    • smoothing: DecimalSource

      The smoothing factor controlling the interpolation speed. A higher value results in slower interpolation.

    • deltaTime: DecimalSource

      The time elapsed since the last frame in seconds.

    Returns Decimal

    • The interpolated value between current and target.
  • How much resource would it cost to buy (numItems) items if you already have currentOwned, the initial price is priceStart and it multiplies by priceRatio each purchase?

    Parameters

    Returns Decimal

  • Tetration: The result of exponentiating 'value' to 'value' 'height' times in a row. https://en.wikipedia.org/wiki/Tetration

    If payload != 1, then this is 'iterated exponentiation', the result of exping 'payload' to base 'value' 'height' times. https://andydude.github.io/tetration/archives/tetration2/ident.html

    Works with negative and positive real heights. Tetration for non-integer heights does not have a single agreed-upon definition, so this library uses an analytic approximation for bases <= 10, but it reverts to the linear approximation for bases > 10. If you want to use the linear approximation even for bases <= 10, set the linear parameter to true. Analytic approximation is not currently supported for bases > 10.

    Parameters

    Returns Decimal

  • Parameters

    • base: number
    • height: number

    Returns number

  • Extracts the integer part of the Decimal and returns it. Behaves like floor on positive numbers, but behaves like ceiling on negative numbers.

    Parameters

    Returns Decimal