SIGN(3) - [NUMERIC] Sign copying function
result = sign(a, b)
elemental type(TYPE(kind=KIND))function sign(a, b)type(TYPE(kind=KIND)),intent(in) :: a, b
o A shall be of type integer or real. o B shall be of the same type as A. o the characteristics of the result are the same as A.
SIGN(3) returns a value with the magnitude of a but with the sign of b.
For processors that distinguish between positive and negative zeros sign() may be used to distinguish between real values 0.0 and -0.0. SIGN (1.0, -0.0) will return -1.0 when a negative zero is distinguishable.
o A : The value whose magnitude will be returned. o B : The value whose sign will be returned.
a value with the magnitude of A with the sign of B. That is,
o If b >= 0 then the result is abs(a) o else if b < 0 it is -abs(a). o if b is real and the processor distinguishes between -0.0 and 0.0 then the result is -abs(a)
Sample program:
program demo_sign implicit none ! basics print *, sign( -12, 1 ) print *, sign( -12, 0 ) print *, sign( -12, -1 ) print *, sign( 12, 1 ) print *, sign( 12, 0 ) print *, sign( 12, -1 )Results:if(sign(1.0,-0.0)== -1.0)then print *, this processor distinguishes +0 from -0 else print *, this processor does not distinguish +0 from -0 endif
print *, elemental, sign( -12.0, [1.0, 0.0, -1.0] )
end program demo_sign
> 12 > 12 > -12 > 12 > 12 > -12 > this processor does not distinguish +0 from -0 > elemental 12.00000 12.00000 -12.00000
FORTRAN 77
ABS(3)
Fortran intrinsic descriptions (license: MIT) @urbanjost
Nemo Release 3.1 | sign (3fortran) | November 02, 2024 |