Manual Reference Pages  - sign (3fortran)

NAME

SIGN(3) - [NUMERIC] Sign copying function

SYNOPSIS

result = sign(a, b)

         elemental type(TYPE(kind=KIND))function sign(a, b)

type(TYPE(kind=KIND)),intent(in) :: a, b

CHARACTERISTICS

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.

DESCRIPTION

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.

OPTIONS

o A : The value whose magnitude will be returned.
o B : The value whose sign will be returned.

RESULT

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)

EXAMPLES

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 )

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

Results:

                 12
                 12
-12 12 12 -12 this processor does not distinguish +0 from -0
elemental
  12.00000 12.00000 -12.00000

STANDARD

FORTRAN 77

SEE ALSO

ABS(3)

fortran-lang intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 sign (3fortran) April 28, 2024
Generated by manServer 1.08 from 6c299209-168f-4793-953c-1b8cc9de9c1e using man macros.