xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

Abs()

Returns the absolute value of a numeric expression.

Syntax

Abs( <nExpression> ) --> nPositive

Arguments

<nExpression>
A numeric expression whose absolute value is calculated.

Return

The function returns the absolute value of the passed argument. The result is always greater than or equal to zero.

Description

The function removes the minus sign from negative numeric values and leaves non-negative values unchanged. This allows for determining the magnitude of numbers regardless of their sign.

Info

See also:Exp(), Int(), Log(), Max(), Min()
Category: Numeric functions
Source:rtl\abs.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates results from Abs()

   PROCEDURE Main()
      LOCAL nVal1 := 200
      LOCAL nVal2 := 900

      ? nVal1 - nVal2                  // result: -700

      ? Abs( nVal1 - nVal2 )           // result:  700
      ? Abs( nVal2 - nVal1 )           // result:  700

      ? Abs( 0 )                       // result: 0
      ? Abs( -700 )                    // result: 700
   RETURN NIL

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe