SIGN(A, B)

Purpose

Returns the absolute value of A times the sign of B. If A is non-zero, you can use the result to determine whether B is negative or non-negative, as the sign of the result is the same as the sign of B.

Note that if you have declared B as REAL(4) or REAL(8), and B has a negative zero value, the sign of the result depends on whether you have specified the -qxlf90=signedzero compiler option.

Class

Elemental function

Argument type and attributes

A
An INTENT(IN) INTEGER or REAL
B
An argument of the same type and kind type parameter as A.

Result type and attributes

Same as A.

Result value

The result is sgn*|A|, where:
  • sgn = -1, if either of the following is true:
    • B < 0
    • B is a REAL(4) or REAL(8) number with a value of negative 0, and you have specified the -qxlf90=signedzero option
  • sgn = 1, otherwise.

Fortran 95 allows a processor to distinguish between a positive and a negative real zero, whereas Fortran 90 did not. Using the -qxlf90=signedzero option allows you to specify the Fortran 95 behavior (except in the case of REAL(16) numbers), which is consistent with the IEEE standard for binary floating-point arithmetic. -qxlf90=signedzero is the default for the xlf95, xlf95_r, xlf95_r7, f95, xlf2003, xlf2003_r, xlf2008, xlf2008_r, f2003, and f2008 invocation commands.

Examples

SIGN (-3.0, 2.0) has the value 3.0.

Specific Name Argument Type Result Type Pass As Arg?
SIGN default real default real yes
ISIGN any integer  1  same as argument yes
DSIGN double precision real double precision real yes
QSIGN REAL(16) REAL(16) yes  2 
Note:
  •  1  IBM extension: the ability to specify a nondefault integer argument.
  •  2  IBM extension: the ability to pass the name as an argument.

Related information

See -qxlf90 in the XL Fortran Compiler Reference.