[Bug fortran/40675] sign intrinsic fails for value of 0.0

kargl at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Tue Jul 7 20:05:00 GMT 2009



------- Comment #6 from kargl at gcc dot gnu dot org  2009-07-07 20:05 -------
(In reply to comment #3)

> OK, so I should instead be submitting a bug report for intel and g77 and 
> pgi.  gfortran is the only correct implementation?

g77 is no longer supported.  You can do want you want with bug
reports to intel and pgi.  But you should fix your code.  Here's
the output with a few PRINTs added to your original code.

REMOVE:kargl[214] ./z
  0.50000000     -0.50000000    
   1.0000000      1.05696461E+09
 fail

Here's the output after I fixed your code.
REMOVE:kargl[216] ./z
  0.50000000     -0.50000000    
   1.0000000      0.50000000    
 fail

Here's the fixed code.

      program main
      real, external :: mysign
      val = 0.0
      test = sign(0.5, val) - sign(0.5, -val)
      test2 = mysign(0.5, val)

      print *, sign(0.5, val), sign(0.5, -val)
      print *, test, test2

      if (test .ne. test2) then
        write (*,*) 'fail'
      else
        write (*,*) 'pass'
      end if
      stop
      end

      real function mysign(a, b)
C ...Returns `ABS(A)*s', where s is +1 if `B.GE.0', -1 otherwise. 
      if (b .ge. 0) then
        s = 1.0
      else
        s = -1.0
      end if
      mysign = abs(a) * s
      return
      end


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40675



More information about the Gcc-bugs mailing list