sahp7641> /var/scratch2/gcc4/bin/gfortran -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.4.0/configure --prefix=/var/scratch2/gcc4/
--enable-languages=c++,c,fortran --with-mpfr=/var/scratch2
Thread model: posix
gcc version 4.4.0 (GCC)
The sign intrinsic gives an incorrect value when the second argument is 0.0:
program main
val = 0.0
test = sign(0.5, val) - sign(0.5, -val)
test2 = mysign(0.5, val)
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
The function 'mysign' implements the definition of the sign function listed at
http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Sign-Intrinsic.html.
When run with gfortran (versions 4.1.2 and 4.4.0 at least), the executable
prints 'fail'. When built with g77 or intel fortran, it prints 'pass' as
expected.
The reason I classified this as a major bug is that old fortran vector codes
use the following idiom to detect a zero value:
test = sign(0.5, val) + sign(0.5, -val)
ratio = value2 / (val + test)
If val is zero, then test would be 1.0 and ratio ends up with a defined value.
Later on outside the vector loop, error checking is done to catch the potential
bad values.
--
Summary: sign intrinsic fails for value of 0.0
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gdsjaar at sandia dot gov
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40675