ABS

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

Syntax

result = ABS (a)

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

Results:

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
  INTEGER(1) INTEGER(1)
IIABS INTEGER(2) INTEGER(2)
IABS 1 INTEGER(4) INTEGER(4)
KIABS INTEGER(8) INTEGER(8)
ABS REAL(4) REAL(4)
DABS REAL(8) REAL(8)
QABS 2 REAL(16) REAL(16)
CABS 3  COMPLEX(4)  REAL(4) 
CDABS 4  COMPLEX(8)  REAL(8) 
CQABS 2   COMPLEX(16)  REAL(16) 
1 Or JIABS. For compatibility with older versions of Fortran, IABS can also be specified as a generic function.
2 VMS and U*X
3 The setting of compiler option /real_size can affect CABS.
4 This function can also be specified as ZABS.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

Examples

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