Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Component

Immutable, arbitrary precision decimal numbers. A Component consists of an integer part and a decimal part stored as string objects. The precision of the number is completely controlled by the user. A MathContext object helps to specify the number of decimal places (not significant figures) the user wants and what rounding algorithm should be used. Every operation is carried out by an intermediate result which is then rounded to the preferred number of decimal places using the preferred rounding algorithm.

Hierarchy

Index

Constructors

constructor

Properties

decimal

decimal: string

The decimal part of the number.

integer

integer: string

The integer part of the number.

Static E

E: Component = new Component({integer: "2", decimal: "7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274"})

The constant Euler's number (\( e \)) correct up to 100 decimal places.

Source: http://paulbourke.net/miscellaneous/numbers/

Static EIGHT

EIGHT: Component = new Component({integer: "8", decimal: ""})

The constant eight.

Static FIVE

FIVE: Component = new Component({integer: "5", decimal: ""})

The constant five.

Static FOUR

FOUR: Component = new Component({integer: "4", decimal: ""})

The constant four.

Static NINE

NINE: Component = new Component({integer: "9", decimal: ""})

The constant nine.

Static ONE

ONE: Component = new Component({integer: "1", decimal: ""})

The constant one.

Static PI

PI: Component = new Component({integer: "3", decimal: "1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"})

The circle constant \( \pi \) correct up to 100 decimal places.

Source: http://paulbourke.net/miscellaneous/numbers/

Static SEVEN

SEVEN: Component = new Component({integer: "7", decimal: ""})

The constant seven.

Static SIX

SIX: Component = new Component({integer: "6", decimal: ""})

The constant six.

Static THREE

THREE: Component = new Component({integer: "3", decimal: ""})

The constant three.

Static TWO

TWO: Component = new Component({integer: "2", decimal: ""})

The constant two.

Static ZERO

ZERO: Component = new Component({integer: "", decimal: ""})

The constant zero.

Static ln10

ln10: Component = new Component({integer: "2", decimal: "3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983"})

The natural logarithm of \( 10 \) correct up to 100 decimal places. This comes in very handy for natural base to common base logarithm.

Source: http://paulbourke.net/miscellaneous/numbers/

Static ln2

ln2: Component = new Component({integer: "", decimal: "6931471805599453094172321214581765680755001343602552541206800094933936219696947156058633269964186875"})

The natural logarithm of \( 2 \) correct up to 100 decimal places.

Accessors

classRef

neg

sign

  • get sign(): 1 | 0 | -1

Methods

add

compareTo

  • The comparator function. This compares this to that and returns

    • 0 if they are equal
    • 1 if this > that
    • -1 if this < that

    Parameters

    Returns 1 | 0 | -1

div

equals

  • Checks whether this and that are equal numbers. Equality is checked only till the number of decimal places specified by mathenv.mode.

    Parameters

    • that: Component

      The number to check against.

    Returns boolean

  • Checks whether this and that are equal numbers. Equality is checked only till the number of decimal places specified by context.

    Parameters

    Returns boolean

getDefinition

  • getDefinition(methodName: string): "instance" | "static" | "undefined"
  • Checks whether a method exists on the object or as a static member of the class.

    Parameters

    • methodName: string

      Name of the method.

    Returns "instance" | "static" | "undefined"

lessEquals

  • Determines whether this is less than or equal to that. Equality is check according to mathenv.mode.

    Parameters

    Returns boolean

  • Determines whether this is less than or equal to that. Equality is checked according to the given context settings.

    Parameters

    Returns boolean

lessThan

mod

  • The modulo operator. The extended definition for non-integer numbers has been used. For two numbers \( a \) and \( b \), \[ a \bmod b = a - b \left\lfloor \frac{a}{b} \right\rfloor \] The result is rounded according to mathenv.mode.

    Parameters

    Returns Component

  • The modulo operator. The extended definition for non-integer numbers has been used. For two numbers \( a \) and \( b \), \[ a \bmod b = a - b \left\lfloor \frac{a}{b} \right\rfloor \] The result is rounded according to the given context.

    Parameters

    Returns Component

moreEquals

  • Determines whether this is more than or equal to that. Equality is checked according to mathenv.mode.

    Parameters

    Returns boolean

  • Determines whether this is more than or equal to that. Equality is checked according to the given context.

    Parameters

    Returns boolean

moreThan

mul

  • Multiplies two Component instances. The sum of the precisions of the two is chosen as the precision of the result and rounding is according to mathenv.mode.

    Parameters

    • that: Component

      The number to multiply this with.

    Returns Component

    this * that.

  • Multiplies two Component instances. The sum of the precisions of the two is chosen as the precision of the result and rounding is according to the given context settings.

    Parameters

    • that: Component

      The number to multiply this with.

    • context: MathContext

      The context settings object to use.

    Returns Component

    this * that.

pow

sub

  • Subtracts one Component instance from another. The higher precision value of the two is chosen as the precision for the result and rounding is according to mathenv.mode.

    Parameters

    • that: Component

      The number to subtract from this.

    Returns Component

    this - that.

  • Subtracts one Component instance from another. The higher precision value of the two is chosen as the precision for the result and rounding is according to the given context settings.

    Parameters

    • that: Component

      The number to subtract from this.

    • context: MathContext

      The context settings object to use.

    Returns Component

    this - that.

toString

  • toString(): string
  • The canonical representation of the number as a string.

    Returns string

    The string representation of this.

Static abs

Static acos

Static acosh

Static asin

Static asinh

Static atan

Static atan2

Static atanh

Static ceil

Static cos

Static cosh

Static create

  • Creates a Component instance from the string representation of the number.

    Parameters

    • num: number

      The string representation of the number in decimal system.

    Returns Component

  • Creates a Component instance from the decimal representation of the number. This instance created will store the exact binary floating point value of the number. Even though it uses the toString() method to convert the number to a string it might be unpredictable at times.

    Parameters

    • num: string

      A numeric expression.

    Returns Component

  • Creates a Component instance from the integral and fractional part of the number. Both the arguments are expected to be string representations of integers.

    Parameters

    • integer: string

      The whole part of the number.

    • fraction: string

      The fractional part of the number.

    Returns Component

Static exp

Static floor

Static intpow

  • Raises a Component to an integer power. This function may be made private in future versions. It is advised not to use this function except for development purposes.

    Parameters

    • base: Component

      The base number.

    • index: number

      The index / exponent to which the base is to be raised.

    • Default value context: object = mathenv.mode

      The context settings to use.

      • precision: number

        The number of decimal places a BigNum object should store. This does not represent the number of significant digits in the number unlike the JAVA implementation of the same concept.

      • rounding: RoundingMode

        The rounding algorithm that should be used for a particular numerical operation. Care must be taken as to when the UNNECESSARY mode is used, it will throw an exception if an exact representation of the result is not found.

    Returns Component

Static ln

Static round

Static sin

Static sinh

Static tan

Static tanh

Generated using TypeDoc