Fortran Wiki
sign

Description

sign(a,b) returns the value of a with the sign of b.

Standard

FORTRAN 77 and later

Class

Elemental function

Syntax

result = sign(a, b)

Arguments

  • a - Shall be of type integer or real
  • b - Shall be of the same type and kind as a

Return value

The kind of the return value is that of a and b. If B0B\ge 0 then the result is abs(a), else it is -abs(a).

Example

program test_sign
  print *, sign(-12,1)
  print *, sign(-12,0)
  print *, sign(-12,-1)

  print *, sign(-12.,1.)
  print *, sign(-12.,0.)
  print *, sign(-12.,-1.)
end program test_sign

category: intrinsics