Intel® Fortran Compiler

Developer Guide and Reference

ID 767251
Date 3/31/2025
Public
Document Table of Contents

ABS

Elemental Intrinsic Function (Generic): Computes an absolute value.

result=ABS(a)

a

(Input) Must be of type integer, real, or complex.

Results

The result has the same type and kind type parameter as a except if a is complex value, the result type is real. If a is an integer or real value, the value of the result is | a |; if a is a complex value (X, Y), the result is the real value SQRT (X**2 + Y**2).

Specific Name

Argument Type

Result Type

BABS

INTEGER(1)

INTEGER(1)

IIABS1

INTEGER(2)

INTEGER(2)

IABS 2

INTEGER(4)

INTEGER(4)

KIABS

INTEGER(8)

INTEGER(8)

ABS

REAL(4)

REAL(4)

Example

ABS (-7.4) has the value 7.4.

ABS ((6.0, 8.0)) has the value 10.0.

The following ABS.F90 program calculates two square roots, retaining the sign:

        REAL mag(2), sgn(2), result(2)
        WRITE (*, '(A)') ' Enter two signed magnitudes: '
        READ (*, *) mag
        sgn = SIGN((/1.0, 1.0/), mag) ! transfer the signs to 1.0s
        result = SQRT (ABS (mag))
! Restore the sign by multiplying by -1 or +1:
        result = result * sgn
        WRITE (*, *) result
        END