API Docs for: 1.0

Class Calculation

Class defined in: src/js/Calculation.js:15

Class to compute the result of an operation of two ordinal numbers.

The intended usage to perform an arithmetic operation is as follows: First, you create a Calculation object by invoking the constructor. Then you invoke the simplify-Method on the object, which returns a normalized Ordinal as an object of type Ord. When comparing two Ordinals (type Ord) against each other, directly call the static Calculation.compare method. All other methods should not be used from outside the class.

Calculation( leftOpnd, rightOpnd, optor )
src/js/Calculation.js:15
Parameters:
  • leftOpnd <Operand / Ord / OrdSummand / number>
  • rightOpnd <Operand / Ord / OrdSummand / number>
  • optor <Operator>
Boolean checkOpnds( ) /* private method */
src/js/Calculation.js:839

Checks if the operands of the calculation object are of type Ord and have at least one summand (i.e. are not undefined).


Returns: <Boolean> True if operands are of type Ord and have one or more summands, False otherwise.
Number cmpNatural( a, b ) /* private method */
src/js/Calculation.js:684

Compare two integers (type "number") operands.

Parameters:
Returns: <Number> A value greater 0 if argument a is greater than b, a value less than 0 if a is less than b, and the value 0 if a is equal to b
Number cmpNaturalOrdinal( natural, ordinal ) /* private method */
src/js/Calculation.js:649

Compare an Operand of type Ord with a primitive integer operand.

Parameters:
Returns: <Number> If natural is greater than ordinal, a value greater 0; If natural and ordinal are the same size, the value 0; and if natural is less than ordinal, a value less than 0 is returned.
Number compare( a, b )
src/js/Calculation.js:136

The main compare function. Use this method from outside the Calculation class to compare two ordinals -- which may also be of type 'number' -- against each other.

Parameters:
  • a <Ord / number>

    The first operand. Might be an instance of Ord or a simple integer of type 'number'.

  • b <Ord / number>

    The second operand. Same type conventions.


Returns: <Number> The result. A value greater 0 means that a is greater than b, a value less than 0 means that b is greater than a, and the value 0 means that a and b are equal.
Number compareOrdinals( a, b )
src/js/Calculation.js:709

Compare the value of two Ordinal numbers (objects of type Ord).

Parameters:
  • a <Ord>

    The first value to compare

  • b <Ord>

    The second value to compare


Returns: <Number> A value greater 0 if argument a is greater than b, a value less than 0 if a is less than b, and the value 0 if a is equal to b
Ord decreaseOne( ord ) /* private method */
src/js/Calculation.js:764

Decrease the argument "ord" by one, so that: 1 + ( decreaseOne(ord) ) = ord.

Parameters:
  • ord <Ord / number>

Returns: <Ord> The result as an Ord object
Ord expOrdinals( ) /* private method */
src/js/Calculation.js:330

Calculates the ordinal (left ^ right).
Might pass through an exception from the method sFinitePower


Returns: <Ord> the result
Ord multiplyOrdinals( ) /* private method */
src/js/Calculation.js:255

Calculates the ordinal (left * right).


Returns: <Ord> the result
Ord natToOrd( num )
src/js/Calculation.js:821

Converts a value of type 'number' into an Ord object. If num is already an Ord object, it will be returned unchanged.

Parameters:
  • num <Ord / number>

Returns: <Ord> The value num represented by an Ord object
Ord sFinitePower( oBase, nExp, cObj ) /* private method */
src/js/Calculation.js:425

Helper method for expOrdinals(): Calculates the power of an infinite base and a finite exponent. Should only be used from inside the Calculation class.
Throws an error (of type ClassedError) when the exponent is too great.

Parameters:
  • oBase <Ord>

    The Base. Must be an Ordinal. (And should be greater than / equal to omega).

  • nExp <Number>

    The exponent. Must be an instance of number!

  • cObj <Calculation>

    Optional. If defined, the static method can register an error to the object.


Returns: <Ord> result The result of the exponentiation.
Ord simplify( )
src/js/Calculation.js:101

Simplifies the expression consisting of left operand, right operand and operator.


Returns: <Ord> The result of the calculation as a normalized object of type Ord.
Ord sInfPower( oBase, oExp, cObj ) /* private method */
src/js/Calculation.js:561

Helper method for expOrdinals(): Calculates the power of an infinite base and an infinite exponent. Should only be used from inside the Calculation class.

Parameters:
  • oBase <Ord>

    The Base. Must be an Ord AND must be greater than / equal to omega.

  • oExp <Ord>

    The exponent. Must be an instance of Ord

  • cObj <Calculation>

    Optional. If defined, the static method can register an error to the object.


Returns: <Ord> The result.
Boolean sIsValidNatural( val )
src/js/Calculation.js:801

Tests if a value is inside a range from 0 to Calculation.maxNatural. Natural numbers shouldn't exceed this value in this application, as there could result inaccurate calculations due to javascripts floating arithmetic.

Parameters:
  • val <Number>

    The value to test


Returns: <Boolean> True if val is a valid natural.
Boolean sIsValueNull( val ) /* private method */
src/js/Calculation.js:782

Static function to check if value is 0, whether it is of type Ord or a number.

Parameters:
  • val <Ord / number>

Returns: <Boolean> True, if val === 0 or val.equalsNull()
Ord sumOrdinals( ) /* private method */
src/js/Calculation.js:193

Calculates the ordinal sum of (left + right).


Returns: <Ord> the result
calcErr <ClassedError>
src/js/Calculation.js:55

If there is an error message, then that indicates that an error has occurred

left <Ord>
src/js/Calculation.js:37

The left operand.

optor <String>
src/js/Calculation.js:49

The operator. Possible values are "^", "*", "+".

right <Ord>
src/js/Calculation.js:43

The right operand.