Click or drag to resize

Abs Function

X#
Return the absolute value of a numeric expression, regardless of its sign.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION Abs(
	nValue AS USUAL
) AS USUAL
Request Example View Source

Parameters

nValue
Type: Usual
The numeric expression to evaluate.

Return Value

Type: Usual
A positive number or 0.
Remarks
Absolute value is the same as nValue if nValue is greater than or equal to 0.
It is the negation of nValue if nValue is less than 0.
Abs() lets you get the difference between the magnitude of
two numbers, where magnitude is the distance from the origin or zero.
Examples
These examples show typical results from Abs():
X#
 1nNum1 := 100
 2nNum2 := 150
 3? nNum1 - nNum2                // -50
 4? ABS(nNum1 - nNum2)            //  50
 5? ABS(nNum2 - nNum1)            //  50
 6? ABS(-12)                    //  12
 7? ABS(0)                    //  0
 8nSouth := -5
 9nNorth := 4
10? ABS(nSouth) - ABS(nNorth)        // 1
11? ABS(nSouth) > ABS(nNorth)        // TRUE
12? nSouth > nNorth            // FALSE
See Also