Seen on intel architectures (i686, x86_64). Run following example code:
program test
complex cres1, cres2, ivc
parameter(ivc = (0,1))
const= 0
fact = 0.5
cres1 = csqrt(const + ivc*fact)
cres2 = csqrt(const - ivc*fact)
print*,'cres1=',cres1, 'cres2=',cres2
const= 1.e-30
cres1 = csqrt(const + ivc*fact)
cres2 = csqrt(const - ivc*fact)
print*,'cres1=',cres1, 'cres2=',cres2
stop
end
The result is:
cres1= ( 0.5000000 , 0.5000000 ) cres2= (-0.5000000 , 0.5000000 )
cres1= ( 0.5000000 , 0.5000000 ) cres2= ( 0.5000000 ,-0.5000000 )
The first line shows the wrong result, the second is that what one expects.
The compiler used it taken from gcc SVN. gfortran -v gives:
gcc version 4.1.0 20051118 (experimental)
--
Summary: sqrt, csqrt may give a wrong result if real part of
compex argument is zero
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libfortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: harald dot vogt at desy dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25017