This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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



------- Comment #8 from gdsjaar at sandia dot gov  2009-07-07 20:13 -------
Subject: Re:  sign intrinsic fails for value of 0.0

OK, sorry for the buggy example code.  It illustrates the folly of 
improving the code after doing the runs. A better fixed code 
illustrating my point is:

      program main
      val = 0.0
      test = sign(0.5, val) - sign(0.5, -val)

      test2 = ysign(0.5, val) - ysign(0.5, -val)
      if (test .ne. test2) then
        write (*,*) 'fail'
      else
        write (*,*) 'pass'
      end if
      stop
      end

      real function ysign(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
      ysign = abs(a) * s
      return
      end



kargl at gcc dot gnu dot org wrote:
> ------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]