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
The system function mathLib.abs returns the absolute value of a number.
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.
myItem = -5; result = mathLib.abs(myItem); // result = 5
Related reference
Mathematical (system words)
The system function mathLib.acos returns the arccosine of an argument, in radians.
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.
result = mathLib.acos(myItem);
Related reference
Mathematical (system words)
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.
result = mathLib.asin(myItem);
Related reference
Mathematical (system words)
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.
result = mathLib.atan(myItem);
Related reference
Mathematical (system words)
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.
myItemY = 1; myItemX = 5; // returns pi/2 result = mathLib.atan2(myItemY, myItemX);
Related reference
Mathematical (system words)
The system function mathLib.ceiling returns the smallest integer not less than a specified number.
myItem = 4.5; result = mathLib.ceiling(myItem); // result = 5
Related reference
Mathematical (system words)
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.
myItem01 = 4 myItem02 = 7 result = mathLib.compareNum(myItem01,myItem02); // result = -1
Related reference
Mathematical (system words)
The system function mathLib.cos returns the cosine of a number. The returned value is in the range of -1 to 1.
result = mathLib.cos(myItem);
Related reference
Mathematical (system words)
The system function mathLib.cosh returns the hyperbolic cosine of a number.
result = mathLib.cosh(myItem);
Related reference
Mathematical (system words)
The system function mathLib.exp returns e raised to the power of a number.
result = mathLib.exp(myItem);
Related reference
Mathematical (system words)
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.
result = mathLib.floatingAssign(myItem);
Related reference
Mathematical (system words)
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.
result = mathLib.floatingDifference(myItem01,myItem02);
Related reference
Mathematical (system words)
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.
result = mathLib.floatingMod(myItem01,myItem02);
Related reference
Mathematical (system words)
The system function mathLib.floatingProduct returns the product of two numbers. The function is implemented using double-precision floating-point arithmetic.
result = mathLib.floatingProduct(myItem01,myItem02);
Related reference
Mathematical (system words)
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.
result = mathLib.floatingQuotient(myItem01,myItem02);
Related reference
Mathematical (system words)
The system function mathLib.floatingSum returns the sum of two numbers. The function is implemented using double-precision floating-point arithmetic.
result = mathLib.floatingSum(myItem01,myItem02);
Related reference
Mathematical (system words)
The system function mathLib.floor returns the largest integer not greater than a specified number.
myItem = 4.6; result = mathLib.floor(myItem); // result = 4
Related reference
Mathematical (system words)
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).
result = mathLib.frexp(myItem,myInteger);
Related reference
Mathematical (system words)
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.
result = mathLib.ldexp(myItem,myInteger);
Related reference
Mathematical (system words)
The system function mathLib.log returns the natural logarithm of a number.
result = mathLib.log(myItem);
Related reference
Mathematical (system words)
The system function mathLib.log10 returns the base 10 logarithm of a number.
result = mathLib.log10(myItem);
Related reference
Mathematical (system words)
The system function mathLib.maximum returns the greater of two numbers.
result = mathLib.maximum(myItem01,myItem02);
Related reference
Mathematical (system words)
The system function mathLib.minimum returns the lesser of two numbers.
result = mathLib.minimum(myItem01,myItem02);
Related reference
Mathematical (system words)
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.
result = mathLib.modf(myItem01,myItem02);
Related reference
Mathematical (system words)
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.
result = mathLib.pow(myItem01,myItem02);
Related reference
Mathematical (system words)
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.
result = mathLib.precision(myItem);
Related reference
Mathematical (system words)
The system function mathLib.round rounds a number or expression to a nearest value (for example, to the nearest thousands) and returns the 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.
You cannot use mathLib.round with the remainder operator (%).
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.
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)
The system function mathLib.sin that returns the sine of a number. The result is in the range of -1 to 1.
result = mathLib.sin(myItem);
Related reference
Mathematical (system words)
The system function mathLib.sinh returns the hyperbolic sine of a number.
result = mathLib.sinh(myItem);
Related reference
Mathematical (system words)
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.
result = mathLib.sqrt(myItem);
Related reference
Mathematical (system words)
The system function mathLib.tan returns the tangent of a number.
result = mathLib.tan(myItem);
Related reference
Mathematical (system words)
The system function mathLib.tanh returns the hyperbolic tangent of a number. The result is in the range of -1 to 1.
result = mathLib.tanh(myItem);
Related reference
Mathematical (system words)
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.