Represents a fixed-point number for precision arithmetic.

Implements

Constructors

Properties

edgeFlag: number

Edge Flag denotes the NaN or NEGATIVE_INFINITY or POSITIVE_INFINITY value.

If ef is not zero, fractionalDigits and scaledValue are not meaningful.

fractionalDigits: bigint

Fractional Digits or decimal places.

scaledValue: bigint

Scaled Value = value * 10 ^ fractionalDigits.

DEFAULT_FRACTIONAL_DECIMALS = 20n

The default number of decimal places to use for fixed-point math.

NaN: FixedPointNumber = ...

Not a Number.

fractionalDigits and scaledValue not meaningful.

NEGATIVE_INFINITY: FixedPointNumber = ...

The negative Infinity value.

ONE: FixedPointNumber = ...

Represents the one constant.

POSITIVE_INFINITY: FixedPointNumber = ...

The positive Infinite value.

ZERO: FixedPointNumber = ...

Represents the zero constant.

Accessors

  • get bi(): bigint
  • Returns the integer part of this FixedPointNumber value.

    Returns bigint

    the integer part of this FixedPointNumber value.

    If the value is not finite.

Methods

  • Compares this instance with that FixedPointNumber instance.

    • Returns null if either instance is NaN;
    • Returns 0 if this is equal to that FixedPointNumber, including infinite with equal sign;
    • Returns -1, if this is -Infinite or less than that FixedPointNumber;,
    • Returns 1 if this is +Infinite or greater than that FixedPointNumber.

    Parameters

    Returns number

    A null if either instance is NaN; -1, 0, or 1 if this instance is less than, equal to, or greater than the specified instance, respectively.

    This method uses internally compareTo wrapping the InvalidOperation exception when comparing between NaN values to behave according the [bignumber.js comparedTo] rules.

  • Compares this instance with that FixedPointNumber instance.

    • Returns 0 if this is equal to that FixedPointNumber, including infinite with equal sign;
    • Returns -1, if this is -Infinite or less than that FixedPointNumber;,
    • Returns 1 if this is +Infinite or greater than that FixedPointNumber.

    Parameters

    Returns number

    Returns -1, 0, or 1 if this instance is less than, equal to, or greater than the specified instance, respectively.

    InvalidOperation If this or that FixedPointNumber is NaN.

  • Adjust the precision of the floating-point number by the specified number of decimal places.

    Parameters

    • decimalPlaces: number | bigint

      The number of decimal places to adjust to, it must be a positive value.

    Returns FixedPointNumber

    A new FixedPointNumber instance with the adjusted precision.

    InvalidDataType if decimalPlaces is negative.

  • Returns true if the value of thisFPN is equal to the value of that FixedPointNumber, otherwise returns false.

    As with JavaScript, NaN does not equal NaN.

    Parameters

    Returns boolean

    true if the FixedPointNumber numbers are equal, otherwise false.

    This method uses eq internally.

  • Returns true if the value of this FixedPointNumber is less than the value of that FixedPointNumber, otherwise returns false.

    Parameters

    Returns boolean

    true if the value of this FixedPointNumber is less than the value of that FixedPointNumber, otherwise returns false.

    This method uses comparedTo internally.

  • Returns a FixedPointNumber whose value is the value of this FixedPointNumber minus that FixedPointNumber.

    Limit cases

    • NaN - ±n = NaN
    • ±n - NaN = NaN
    • -Infinity - -Infinity = NaN
    • -Infinity - +n = -Infinity
    • +Infinity - +Infinity = NaN
    • +Infinity - +n = +Infinity

    Parameters

    Returns FixedPointNumber

    The result of the subtraction. The return value is always exact and unrounded.

    The precision is the greater of the precision of the two operands.

  • Returns a FixedPointNumber whose value is the value of this FixedPointNumber modulo that FixedPointNumber, i.e. the integer remainder of dividing this FixedPointNumber by that.

    Limit cases

    • NaN % ±n = NaN
    • ±n % NaN = NaN
    • ±Infinity % n = NaN
    • n % ±Infinity = NaN

    Parameters

    • that: FixedPointNumber

      {FixedPointNumber} - The fixed-point number to divide by.

    Returns FixedPointNumber

    the integer remainder of dividing this FixedPointNumber by that.

    The precision is the greater of the precision of the two operands.

  • Returns a FixedPointNumber whose value is the value of this FixedPointNumber plus that FixedPointNumber.

    Limit cases

    • NaN + ±n = NaN
    • ±n + NaN = NaN
    • -Infinity + -Infinity = -Infinity
    • -Infinity + +Infinity = NaN
    • +Infinity + -Infinity = NaN
    • +Infinity + +Infinity = +Infinity

    Parameters

    Returns FixedPointNumber

    The result of the addition. The return value is always exact and unrounded.

    The precision is the greater of the precision of the two operands.

  • Returns a FixedPointNumber whose value is the value of this FixedPointNumber multiplied by that FixedPointNumber.

    Limits cases

    • NaN * n = NaN
    • n * NaN = NaN
    • -Infinite * -n = +Infinite
    • -Infinite * +n = -Infinite
    • +Infinite * -n = -Infinite
    • +Infinite * +n = +Infinite

    Parameters

    Returns FixedPointNumber

    a FixedPointNumber whose value is the value of this FixedPointNumber multiplied by that FixedPointNumber.

    The precision is the greater of the precision of the two operands.

  • Converts the fixed-point number to its string representation.

    Parameters

    • OptionaldecimalSeparator: string = '.'

      The character to use as the decimal separator in the string representation. Default is '.'.

    Returns string

    A string representation of the fixed-point number.

  • Checks if a given string expression is an integer in base 10 notation, considering - for negative and + optional for positive values.

    Parameters

    • exp: string

      The string expression to be tested.

    Returns boolean

    true if the expression is an integer, false otherwise.

  • Checks if a given string expression is a natural (unsigned positive integer) number in base 10 notation.

    Parameters

    • exp: string

      The string expression to be tested.

    Returns boolean

    true if the expression is a natural number, false otherwise.

  • Checks if a given string expression is a number in base 10 notation, considering - for negative and + optional for positive values.

    The method returns true for the following cases.

    • Whole numbers:
      • Positive whole numbers, optionally signed: 1, +2, 3, ...
      • Negative whole numbers: -1, -2, -3, ...
    • Decimal numbers:
      • Positive decimal numbers, optionally signed: 1.0, +2.5, 3.14, ...
      • Negative decimal numbers: -1.0, -2.5, -3.14, ...
      • Decimal numbers without whole part:
        • Positive decimal numbers, optionally signed: .1, +.5, .75, ...
        • Negative decimal numbers: -.1, -.5, -.75, ...

    Parameters

    • exp: string

      The string expression to be checked.

    Returns boolean

    true is exp represents a number, otherwise false.

  • Constructs a new instance of FixedPointNumber (Fixed Point Number) parsing the exp numeric expression in base 10 and representing the value with the precision of decimalPlaces fractional decimal digits.

    Parameters

    • exp:
          | string
          | number
          | bigint
          | FixedPointNumber

      The value to represent. It can be a bigint, number, or string representation of the number.

    • OptionaldecimalPlaces: bigint = ...

      The number of fractional decimal digits to be used to represent the value.

    Returns FixedPointNumber

    A new instance of FixedPointNumber with the given parameters.

    If exp is not a numeric expression.