ABS Function

The ABS function returns the absolute value of the given expression.

Format

ABS(expr)

Parameter(s)

expr

An expression evaluating to a numeric value.

Description

The absolute value of any expression is defined mathematically as its positive value; that is, the difference between itself and 0. The absolute value of any positive expression is itself, and the absolute value of a negative expression is calculated by reversing the sign—that is; the absolute value of -n  is n. If expr does not evaluate to a numeric value, the ABS function returns 0.

Example

If the variable NUMBER contains -1.732, then

ABS(NUMBER)

returns 1.732.

In the next application the ABS function is used to discover an error in bookkeeping. Note that in the printing of the discrepancy, a form of the FMT format function has been used to make the data more readable.

DIFF = ABS(PRICE - COST - PROFIT)

IF DIFF THEN

   PRINT "ERROR OF  " : DIFF " 2,$ " : " . PLEASE CHECK."

END

If the PRICE has been established as 9.99, the COST is 4.25, and the estimated PROFIT has been set at 5.75, the resulting output is:

ERROR OF  $0.01. PLEASE CHECK.

See Also

Statement and Function Reference