The following mathematical functions are supported in arithmetic
processing statements (ADD
,
COMPUTE
,
DIVIDE
,
MULTIPLY
,
SUBTRACT
) and in
logical condition criteria:
Function | Format/Length | Explanation |
---|---|---|
ABS(field)
|
same as field
|
Absolute value of
field .
|
ATN(field)
|
F8 | Arc tangent of
field .
|
COS(field)
|
F8 |
Cosine of field. If the value of the field is
equal to or greater than 1017,
|
EXP(field)
|
F8 | Exponentiation of exponent field to base e , that is, efield, where e is Euler's number. |
FRAC(field)
|
same as field
|
Fractional part of
field .
|
INT(field)
|
same as field
|
Integer part of
field .
|
LOG(field)
|
F8 | Natural logarithm of
field .
|
SGN(field)
|
same as field
|
Sign of field (-1, 0,
+1).
|
SIN(field)
|
F8 |
Sine of If the value of the
|
SQRT(field)
|
(*) |
Square root of A negative value in the argument field will be treated as positive. The maximum number of digits before the decimal point of the argument is 22. |
TAN(field)
|
F8 |
Tangent of If the value of the
|
VAL(field)
|
same as target field |
Extract numeric value from an alphanumeric
If the target field is not long enough, decimal digits will be truncated (see also Field Truncation and Field Rounding in the section Rules for Arithmetic Assignment of the Programming Guide). |
* These functions are evaluated as follows:
If field
has format/length F4,
format/length of SQRT(field)
will be
F4.
If field
has format/length F8
or I, format/length of SQRT(field)
will
be F8.
If field
has format N or P,
format/length of SQRT(field)
will be
Nn
.7 or Pn.7
respectively (where n
is automatically
calculated to be large enough).
A field
to be used with a
mathematical function - except VAL
- may be a constant or a
scalar; its format must be numeric (N), packed numeric (P), integer (I), or
floating point (F).
A field
to be used with the
VAL
function may be a constant, a scalar, or an array; its format
must be alphanumeric.
** Example 'MATHEX': Mathematical functions ************************************************************************ DEFINE DATA LOCAL 1 #A (N2.1) INIT <10> 1 #B (N2.1) INIT <-6.3> 1 #C (N2.1) INIT <0> 1 #LOGA (N2.6) 1 #SQRTA (N2.6) 1 #TANA (N2.6) 1 #ABS (N2.1) 1 #FRAC (N2.1) 1 #INT (N2.1) 1 #SGN (N1) END-DEFINE * COMPUTE #LOGA = LOG(#A) WRITE NOTITLE '=' #A 5X 'LOG' 40T #LOGA * COMPUTE #SQRTA = SQRT(#A) WRITE '=' #A 5X 'SQUARE ROOT' 40T #SQRTA * COMPUTE #TANA = TAN(#A) WRITE '=' #A 5X 'TANGENT' 40T #TANA * COMPUTE #ABS = ABS(#B) WRITE // '=' #B 5X 'ABSOLUTE' 40T #ABS * COMPUTE #FRAC = FRAC(#B) WRITE '=' #B 5X 'FRACTIONAL' 40T #FRAC * COMPUTE #INT = INT(#B) WRITE '=' #B 5X 'INTEGER' 40T #INT * COMPUTE #SGN = SGN(#A) WRITE // '=' #A 5X 'SIGN' 40T #SGN * COMPUTE #SGN = SGN(#B) WRITE '=' #B 5X 'SIGN' 40T #SGN * COMPUTE #SGN = SGN(#C) WRITE '=' #C 5X 'SIGN' 40T #SGN * END
Output of program MATHEX
:
#A: 10.0 LOG 2.302585 #A: 10.0 SQUARE ROOT 3.162277 #A: 10.0 TANGENT 0.648360 #B: -6.3 ABSOLUTE 6.3 #B: -6.3 FRACTIONAL -0.3 #B: -6.3 INTEGER -6.0 #A: 10.0 SIGN 1 #B: -6.3 SIGN -1 #C: 0.0 SIGN 0