Name

Abs Function

Syntax

function Abs(Number: Numeric type): Numeric type;

Description

The Abs function computes and returns an absolute value. The function is built into the compiler.

Return Value

  • If the number has an integer type, Abs checks whether the value is negative and if so, negates it. The return type is Integer or Int64, depending on the type of the argument.

  • For a floating-point number, Abs clears the sign bit without altering any other bit. In other words, negative zero and negative infinity become positive zero and positive infinity. Even if the value is NaN, the result is the original number with a zero for the sign bit.

Argument

Return

-infinity

+infinity

< 0

-number

-0.0

+0.0

+0.0

+0.0

> 0.0

number

+infinity

+infinity

quiet NaN

original value with sign bit set to zero

signaling NaN

original value with sign bit set to zero

  • If the argument is a Variant, Delphi converts it to a floating-point number and then takes the absolute value, returning a floating-point result (even if the Variant value is an integer).

See Also

Double Type, Extended Type, Int64 Type, Integer Type, Single Type

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.