Elemental Intrinsic Function (Generic): Returns the absolute value of the first argument times the sign of the second argument.
Syntax
result = SIGN (a, b)
a
(Input) Must be of type integer or real.
b
Must have the same type and kind parameters as a.
Results
The result type is the same as a. The value of the result is | a | if b zero and -| a | if b < zero.
If b is of type real and zero, the value of the result is | a |. However, if the processor can distinguish between positive and negative real zero and the assume minus0 compiler option is specified, the following occurs:
Specific Name | Argument Type | Result Type |
---|---|---|
BSIGN | INTEGER(1) | INTEGER(1) |
IISIGN 1 | INTEGER(2) | INTEGER(2) |
ISIGN 2 | INTEGER(4) | INTEGER(4) |
KISIGN | INTEGER(8) | INTEGER(8) |
SIGN | REAL(4) | REAL(4) |
DSIGN | REAL(8) | REAL(8) |
QSIGN | REAL(16) | REAL(16) |
1 Or HSIGN. 2 Or JISIGN. For compatibility with older versions of Fortran, ISIGN can also be specified as a generic function. |
See Also:
ABS, assume minus0 compiler option
Examples
SIGN (4.0, -6.0) has the value -4.0.
SIGN (-5.0, 2.0) has the value 5.0.
The following shows another example:
c = SIGN (5.2, -3.1) ! returns -5.2
c = SIGN (-5.2, -3.1) ! returns -5.2
c = SIGN (-5.2, 3.1) ! returns 5.2