EGL Reference Guide for iSeries

Mathematical (system words)

Mathematical system words perform operations such as absolute value, cosine, natural log, and rounding. These words operate on items (and return values to items) of the following kinds:

The mathematical system functions can raise exception conditions; but a try ... onException ... end block is necessary if you wish sysVar.errorCode to receive the returned code.

The mathematical functions return the following values for sysVar.errorCode:

The mathematical system words are listed in the next table.


System function/Invocation Description
mathLib.abs
result = mathLib.abs
(numericItem)
Returns absolute value of numericItem
mathLib.acos
result = mathLib.acos
(numericItem)
Returns arccosine of numericItem
mathLib.asin
result = mathLib.asin (numericItem)
Returns arcsine of numericItem
mathLib.atan
result = mathLib.atan
(numericItem)
Returns arctangent of numericItem
mathLib.atan2
result = mathLib.atan2 (y, x)
Computes the principal value of the arc tangent of y/x, using the signs of both arguments to determine the quadrant of the return value
mathLib.ceiling
result = mathLib.ceiling
(numericItem)
Returns smallest integer not less than numericItem
mathLib.compareNum
result = mathLib.compareNum
(numericItem1, numericItem2)
Returns a result (-1, 0, or 1) that indicates whether numericItem1 is less than, equal to, or greater than numericItem2
mathLib.cos
result = mathLib.cos
(numericItem)
Returns cosine of numericItem
mathLib.cosh
result = mathLib.cosh (numericItem)
Returns hyperbolic cosine of numericItem
mathLib.exp
result = mathLib.exp
(numericItem)
Returns exponential value of numericItem
mathLib.floatingAssign
result = mathLib.floatingAssign 
 (numericItem)
Returns numericItem as a double-precision floating-point number
mathLib.floatingDifference
result = mathLib.floatingDifference
(numericItem1, numericItem2)
Returns the difference between numericItem1 and numericItem2
mathLib.floatingMod
result = mathLib.floatingMod
(numericItem1, numericItem2)
Calculates the floating point remainder of numericItem1 divided by numericItem2, with the result having the same sign as numericItem1
mathLib.floatingProduct
result = mathLib.floatingProduct
(numericItem1, numericItem2)
Returns product of numericItem1 and numericItem2
mathLib.floatingQuotient
result = mathLib.floatingQuotient
(numericItem1, numericItem2)
Returns quotient of numericItem1 divided by numericItem2
mathLib.floatingSum
result = mathLib.floatingSum
(numericItem1, numericItem2)
Returns sum of numericItem1 and numericItem2
mathLib.floor
result = mathLib.floor
(numericItem)
Returns the largest integer not greater than numericItem
mathLib.frexp
result = mathLib.frexp
(numericItem, integer)
Splits a number into a normalized fraction in the range of .5 to 1 (which is the returned value) and a power of 2 (which is returned in integer
mathLib.ldexp
result = mathLib.ldexp
(numericItem, integer)
Returns numericItem multiplied by 2 to the power of integer
mathLib.log
result = mathLib.log
(numericItem)
Returns the natural logarithm of numericItem
mathLib.log10
result = mathLib.log10
(numericItem)
Returns the base 10 logarithm of numericItem
mathLib.maximum
result = mathLib.maximum
(numericItem1, numericItem2)
Returns the greater of numericItem1 and numericItem2
mathLib.minimum
result = mathLib.minimum
(numericItem1, numericItem2)
Returns the lesser of numericItem1 and numericItem2
mathLib.modf
result = mathLib.modf
(numericItem1, numericItem2)
Splits numericItem1 into integral and fractional parts, both with the same sign as numericItem1; places the integral part in numericItem2; and returns the fractional part
mathLib.pow
result = mathLib.pow
(numericItem1, numericItem2)
Returns numericItem1 raised to the power of numericItem2
mathLib.precision
result = mathLib.precision
(numericItem)
Returns the maximum precision (in decimal digits) for numericItem
mathLib.round
result = mathLib.round
(numericItem, integer)
result = mathLib.round
(numericExpression)
Rounds a number or expression to a nearest value (for example, to the nearest thousands) and returns the result
mathLib.sin
result = mathLib.sin
(numericItem)
Returns sine of numericItem
mathLib.sinh
result = mathLib.sinh
(numericItem)
Returns hyperbolic sine of numericItem
mathLib.sqrt
result = mathLib.sqrt
(numericItem)
Returns the square root of numericItem if numericItem is greater than or equal to zero
mathLib.tan
result = mathLib.tan
(numericItem)
Returns the tangent of numericItem
mathLib.tanh
result = mathLib.tanh
(numericItem)
Returns the hyperbolic tangent of numericItem


Related reference
Assignments
EGL statements
EGL statements
Exception handling
Numeric expressions
Primitive types
System words
System words in alphabetical order

mathLib.abs

The system function mathLib.abs returns the absolute value of a number.



sysLib.abs syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The absolute value of numericItem is converted to the format of result and returned in result.
numericItem
Any numeric item or HEX item, as described in Mathematical (system words).

mathLib.abs works on every target system. In relation to Java programs, EGL uses one of the abs() methods in the Java StrictMath class so that the run-time behavior is the same for every Java Virtual Machine.

Example
  myItem = -5;
  result = mathLib.abs(myItem);  // result = 5


Related reference
Mathematical (system words)

mathLib.acos

The system function mathLib.acos returns the arccosine of an argument, in radians.



sysLib.acos syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The returned value (between 0.0 and pi) is in radians and is converted to the format of result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating point before the calculation occurs. If the value is not between -1 and 1, an error occurs.

mathLib.acos works on every target system. In relation to Java programs, EGL uses the acos() method in the Java StrictMath class so that the run-time behavior is the same for every Java Virtual Machine.

Example
  result = mathLib.acos(myItem);


Related reference
Mathematical (system words)

mathLib.asin

The system function sysLib.asin returns the arcsine of a number that is in the range of -1 to 1. The result is in radians and is in the range of -pi/2 to pi/2.



sysLib.asin syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by the mathLib.asin function is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating point before the mathLib.asin function is called.

Example
  result = mathLib.asin(myItem);


Related reference
Mathematical (system words)

mathLib.atan

The system function mathLib.atan returns the arctangent of a number. The result is in radians and is in the range of -pi/2 and pi/2.



sysLib.atan syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by mathLib.atan is converted to the format of result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating point before mathLib.atan is called.

Example
  result = mathLib.atan(myItem);


Related reference
Mathematical (system words)

mathLib.atan2

The system function mathLib.atan2 computes the principal value of the arc tangent of y/x, using the signs of both arguments to determine the quadrant of the return value. The result is in radians and is in the range of -pi to pi.



sysLib.atan2 syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by mathLib.atan2 is converted to the format of result and returned in result.
numericItem1
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating point before mathLib.atan2 is called. numericItem1 is the y value.
numericItem2
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating point before mathLib.atan2 is called. numericItem2 is the x value.

Example
  myItemY = 1;
  myItemX = 5;
 
  // returns pi/2
  result = mathLib.atan2(myItemY, myItemX);


Related reference
Mathematical (system words)

mathLib.ceiling

The system function mathLib.ceiling returns the smallest integer not less than a specified number.



sysLib.ceiling syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The smallest integer not less than numericItem is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words).

Example
  myItem = 4.5;
  result = mathLib.ceiling(myItem); // result = 5


Related reference
Mathematical (system words)

mathLib.compareNum

The system function mathLib.compareNum returns a result (-1, 0, or 1) that indicates whether the first of two numbers is less than, equal to, or greater than the second.



mathLib.compareNum syntax diagram

result
Item defined as type INT or the following equivalent: type BIN with length 9 and no decimal places. This item receives one of the following values:

-1
numericItem1 is less than numericItem2.

0
numericItem1 is equal to numericItem2.

1
numericItem1 is greater than numericItem2.
numericItem1
Any numeric or HEX item, as described in Mathematical (system words).
numericItem2
Any numeric or HEX item, as described in Mathematical (system words).

Example
  myItem01 = 4
  myItem02 = 7
 
  result = mathLib.compareNum(myItem01,myItem02);
 
  // result = -1


Related reference
Mathematical (system words)

mathLib.cos

The system function mathLib.cos returns the cosine of a number. The returned value is in the range of -1 to 1.



sysLib.cos syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by mathLib.cos is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before mathLib.cos is called.

Example
  result = mathLib.cos(myItem);


Related reference
Mathematical (system words)

mathLib.cosh

The system function mathLib.cosh returns the hyperbolic cosine of a number.



mathLib.cosh syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by mathLib.cosh is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before mathLib.cosh is called.

Example
  result = mathLib.cosh(myItem);


Related reference
Mathematical (system words)

mathLib.exp

The system function mathLib.exp returns e raised to the power of a number.



mathLib.exp syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by mathLib.exp is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before mathLib.exp is called.

Example
  result = mathLib.exp(myItem);


Related reference
Mathematical (system words)

mathLib.floatingAssign

The system function mathLib.floatingAssign returns numericItem as a double-precision floating-point number. The function assigns the value of BIN, DECIMAL, NUM, NUMC, or PACKF items to floating-point numbers that are defined as HEX items, and vice versa.



mathLib.floatingAssign syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The floating-point number is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before being assigned to the result.

Example
  result = mathLib.floatingAssign(myItem);


Related reference
Mathematical (system words)

mathLib.floatingDifference

The system function mathLib.floatingDifference subtracts the second of two numbers from the first and returns the difference. The function is implemented using double-precision floating-point arithmetic.



mathLib.floatingDifference syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The difference is converted to the format of result and returned in result.
numericItem1
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before the difference is calculated.
numericItem2
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before the difference is calculated.

Example
  result = mathLib.floatingDifference(myItem01,myItem02);


Related reference
Mathematical (system words)

mathLib.floatingMod

The system function mathLib.floatingMod returns the floating-point remainder of one number divided by another. The result has the same sign as the numerator. A domain exception is raised if the denominator equals zero.



mathLib.floatingMod syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The floating-point remainder is converted to the format of result and returned in result.
numericItem1
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.
numericItem2
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.

Example
  result = mathLib.floatingMod(myItem01,myItem02);


Related reference
Mathematical (system words)

mathLib.floatingProduct

The system function mathLib.floatingProduct returns the product of two numbers. The function is implemented using double-precision floating-point arithmetic.



mathLib.floatingProduct syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The product is converted to the format of result and returned in result.
numericItem1
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.
numericItem2
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.

Example
  result = mathLib.floatingProduct(myItem01,myItem02);


Related reference
Mathematical (system words)

mathLib.floatingQuotient

The system function mathLib.floatingQuotient returns the quotient of one number divided by another. A domain exception is raised if the denominator equals zero. The function is implemented using double-precision floating-point arithmetic.



mathLib.floatingQuotient syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The quotient is converted to the format of result and returned in result.
numericItem1
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before the quotient is calculated.
numericItem2
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before the quotient is calculated.

Example
  result = mathLib.floatingQuotient(myItem01,myItem02);


Related reference
Mathematical (system words)

mathLib.floatingSum

The system function mathLib.floatingSum returns the sum of two numbers. The function is implemented using double-precision floating-point arithmetic.



mathLib.floatingSum syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The sum is converted to the format of result and returned in result.
numericItem1
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before the sum is calculated.
numericItem2
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before the sum is calculated.

Example
  result = mathLib.floatingSum(myItem01,myItem02);


Related reference
Mathematical (system words)

mathLib.floor

The system function mathLib.floor returns the largest integer not greater than a specified number.



mathLib.floor syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The largest integer not greater thannumericItem is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words).

Example
  myItem = 4.6;
  result = mathLib.floor(myItem); // result = 4


Related reference
Mathematical (system words)

mathLib.frexp

The system function mathLib.frexp splits a number into a normalized fraction in the range of .5 to 1 (which is returned as the result) and a power of 2 (which is returned in integer).



mathLib.frexp syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The floating-point fraction is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.
integer
Item defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.

Example
  result = mathLib.frexp(myItem,myInteger);


Related reference
Mathematical (system words)

mathLib.ldexp

The system function mathLib.ldexp returns the value of a specified number that is multiplied by the following value: two to the power of integer.



mathLib.ldexp syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The calculated value is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.
integer
Item defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.

Example
  result = mathLib.ldexp(myItem,myInteger);


Related reference
Mathematical (system words)

mathLib.log

The system function mathLib.log returns the natural logarithm of a number.



mathLib.log syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by the mathLib.log function is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.

Example
  result = mathLib.log(myItem);


Related reference
Mathematical (system words)

mathLib.log10

The system function mathLib.log10 returns the base 10 logarithm of a number.



mathLib.log10 syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by the log10 function is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.

Example
  result = mathLib.log10(myItem);


Related reference
Mathematical (system words)

mathLib.maximum

The system function mathLib.maximum returns the greater of two numbers.



mathLib.maximum syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The greater of two numbers is converted to the format of result and returned in result.
numericItem1
Any numeric or HEX item, as described in Mathematical (system words).
numericItem2
Any numeric or HEX item, as described in Mathematical (system words).

Example
  result = mathLib.maximum(myItem01,myItem02);


Related reference
Mathematical (system words)

mathLib.minimum

The system function mathLib.minimum returns the lesser of two numbers.



mathLib.minimum syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The lesser of two numbers is converted to the format of result and returned in result.
numericItem1
Any numeric or HEX item, as described in Mathematical (system words).
numericItem2
Any numeric or HEX item, as described in Mathematical (system words).

Example
  result = mathLib.minimum(myItem01,myItem02);


Related reference
Mathematical (system words)

mathLib.modf

The system function mathLib.modf splits a number into integral and fractional parts, both with the same sign as the number. The fractional part is returned in result and the integral part is returned in numericItem2.



mathLib.modf syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The fractional part of numericItem1 is converted to the format of result and returned in result.
numericItem1
Any numeric or HEX item, as described in Mathematical (system words).
numericItem2
Any numeric or HEX item, as described in Mathematical (system words). The integral part of numericItem1 is converted to the format of numericItem2 and returned in numericItem2.

Example
  result = mathLib.modf(myItem01,myItem02);


Related reference
Mathematical (system words)

mathLib.pow

The system function mathLib.pow returns a number raised to the power of a second number. A domain exception is raised if on pow(x,y) the value of x is negative and y is non-integral, or the value of x is 0.0 and y is negative.



mathLib.pow syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The result of the mathLib.pow function is converted to the format of result and returned in result.
numericItem1
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.
numericItem2
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.

Example
  result = mathLib.pow(myItem01,myItem02);


Related reference
Mathematical (system words)

mathLib.precision

The system function mathLib.precision returns the maximum precision (in decimal digits) for a number. For floating-point numbers (8-digit HEX for standard-precision floating-point number or 16-digit HEX for double-precision floating-point number), the precision is the maximum number of decimal digits that can be represented in the number for the system on which the program is running.



mathLib.precision syntax diagram

result
An item that receives the precision of numericItem. The result item is defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.
numericItem
Any numeric or HEX item, as described in Mathematical (system words).

Example
  result = mathLib.precision(myItem);


Related reference
Mathematical (system words)

mathLib.round

The system function mathLib.round rounds a number or expression to a nearest value (for example, to the nearest thousands) and returns the result.



mathLib.round syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value produced by the rounding operation is converted to the format of result and returned in result.

The maximum supported length in this case is 17 rather than 18 because rounding occurs as follows:

A numeric overflow occurs at run time if more than 17 digits are used in the calculation and if EGL cannot determine the violation at development time.

numericItem
Any numeric or HEX item, as described in Mathematical (system words).
numericExpression
A numeric expression other than simply a numeric item. If you specify an operator, you cannot specify a value for integer.

You cannot use mathLib.round with the remainder operator (%).

integer
An integer that determines the value to which the number is rounded:

If you do not specify integer, mathLib.round rounds to the number of decimal places in result.

The integer is defined as type INT or the following equivalent: type BIN with length 9 and no decimal places.

Examples

In the next example, item balance is rounded to the nearest thousand:

balance = 12345.6789;
rounder = 3;
balance = mathLib.round(balance, rounder);
// The value of balance is now 12000.0000

In the next example, a rounder value of -2 is used to round balance to two decimal places:

balance = 12345.6789;
rounder = -2;
balance = mathLib.round(balance, rounder);
// The value of balance is now 12345.6800


Related reference
Mathematical (system words)

mathLib.sin

The system function mathLib.sin that returns the sine of a number. The result is in the range of -1 to 1.



mathLib.sin syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by the mathLib.sin function is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.

Example
  result = mathLib.sin(myItem);


Related reference
Mathematical (system words)

mathLib.sinh

The system function mathLib.sinh returns the hyperbolic sine of a number.



mathLib.sinh syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by the mathLib.sinh function is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.

Example
  result = mathLib.sinh(myItem);


Related reference
Mathematical (system words)

mathLib.sqrt

The math function mathLib.sqrt returns the square root of a number. The function operates on any number that is greater than or equal to zero.



mathLib.sqrt syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by the mathLib.sqrt function is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.

Example
  result = mathLib.sqrt(myItem);


Related reference
Mathematical (system words)

mathLib.tan

The system function mathLib.tan returns the tangent of a number.



mathLib.tan syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by the mathLib.tan function is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.

Example
  result = mathLib.tan(myItem);


Related reference
Mathematical (system words)

mathLib.tanh

The system function mathLib.tanh returns the hyperbolic tangent of a number. The result is in the range of -1 to 1.



mathLib.tanh syntax diagram

result
Any numeric or HEX item, as described in Mathematical (system words). The value returned by the mathLib.tanh function is converted to the format of result and returned in result.
numericItem
Any numeric or HEX item, as described in Mathematical (system words). The item is converted to double-precision floating-point before result is calculated.

Example
  result = mathLib.tanh(myItem);


Related reference
Mathematical (system words)


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]