EGL library mathLib

The EGL mathLib functions perform common mathematical and trigonometric functions.

The input and output type for most mathLib functions is the FLOAT, so that the functions can operate on a wide range of assignment-compatible values. Note that you might lose some precision in the conversion of decimal values to floating point and back.

The mathLib functions work on every target system, in code generated for both COBOL and Java™. In the case of Java, EGL uses methods in the Java StrictMath class that are equivalent to the EGL functions. This ensures that runtime behavior is the same for every Java Virtual Machine.

Functions

The next table lists the functions in the system library mathLib.

Table 1. mathLib functions
System function/Invocation Description
result = abs (numericVariable) Returns the absolute value of numericVariable.
result = acos (numericVariable) Returns the arc cosine of numericVariable.
result = asin (numericVariable) Returns the arc sine of numericVariable.
assign (source, target) Preserves V6 rounding when assigning the value of source to target.
result = atan (numericVariable) Returns the arc tangent of numericVariable.
result = atan2 (numericVariable1, numericVariable2) Computes the principal value of the arc tangent of numericVariable1/numericVariable2, using the signs of both arguments to determine the quadrant of the return value.
result = ceiling (numericVariable) Returns the smallest integer not less than numericVariable.
result = cos (numericVariable) Returns the cosine of numericVariable.
result = cosh (numericVariable) Returns the hyperbolic cosine of numericVariable.
result = decimals (numericVariable) Returns the number of decimal places defined for numericVariable.
result = exp (numericVariable) Returns the exponential value of numericVariable.
result = floor (numericVariable) Returns the largest integer not greater than numericVariable.
result = frexp (numericVariable, 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).
result = ldexp (numericVariable, integer) Returns numericVariable multiplied by 2 to the power of integer.
result = log (numericVariable) Returns the natural logarithm of numericVariable.
result = log10 (numericVariable) Returns the base 10 logarithm of numericVariable.
result = max (numericVariable1, numericVariable2) Returns the greater of numericVariable1 and numericVariable2.
result = min (numericVariable1, numericVariable2) Returns the lesser of numericVariable1 and numericVariable2.
result = modf (numericVariable1, numericVariable2)
  1. Splits numericVariable1 into integer and fraction parts, both with the same sign as numericVariable1.
  2. Places the integer in numericVariable2.
  3. Returns the fractional part.
result = pow (numericVariable1, numericVariable2) Returns numericVariable1 raised to the power of numericVariable2.
result = precision (numericVariable) Returns the maximum precision (in decimal digits) for numericVariable.
result = round (numericVariable, integer) Rounds a number or expression to a nearest value (for example, to the nearest thousands) and returns the result.
result = sin (numericVariable) Returns the sine of numericVariable.
result = sinh (numericVariable) Returns the hyperbolic sine of numericVariable.
result = sqrt (numericVariable) Returns the square root of numericVariable if numericVariable is greater than or equal to zero.
result = tan (numericVariable) Returns the tangent of numericVariable.
result = tanh (numericVariable) Returns the hyperbolic tangent of numericVariable.

Error conditions

The following table shows how mathLib functions respond to errors. Two different scenarios apply. In the default scenario, EGL throws the exception shown in the second column. The other scenario occurs in V6 exception mode (see Using V6 exception compatibility). In this case, EGL does not throw an exception, and sysVar.errorCode is set to the value in the third column.

Table 2. mathLib errors
Error EGL exception (default) sysVar.errorCode (V6 exceptions)
Invalid input RuntimeException 00000008
Cannot assign value to target variable RuntimeException 00000012
other other 00000016