This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libfortran/24313] New: complex sqrt function does not return principal value
- From: "mick at nag dot co dot uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 11 Oct 2005 17:27:28 -0000
- Subject: [Bug libfortran/24313] New: complex sqrt function does not return principal value
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
This program demonstrates a bug in the complex sqrt function
in gfortran. When complex number x = (0.0,-1.0), the result comes
back as the negative of the expected result. Of course, the negative
of the expected result is still a square root of the original
number, but the f95 standard says that the principal square root
should be returned, i.e. the real part of the result should be positive.
complex x, y
x = cmplx(0.0,-1.0)
y = sqrt(x)
write (*,*) x, y
x = cmplx(0.0+1.0e-38,-1.0)
y = sqrt(x)
write (*,*) x, y
x = cmplx(0.0-1.0e-38,-1.0)
y = sqrt(x)
write (*,*) x, y
end
The results I get are
% gfortran -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc/configure --prefix=/var/tmp/gfortran-20051007/irun
--enable-languages=c,f95
Thread model: posix
gcc version 4.1.0 20051007 (experimental)
% gfortran sqrt.f
% ./a.out
( 0.000000 , -1.000000 ) (-0.7071068 , 0.7071068 )
( 9.9999994E-39, -1.000000 ) ( 0.7071068 ,-0.7071068 )
(-9.9999994E-39, -1.000000 ) ( 0.7071068 ,-0.7071068 )
Using a tiny number in place of the zero real part shows the
correct results.
This also affects the double complex version of sqrt.
--
Summary: complex sqrt function does not return principal value
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libfortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mick at nag dot co dot uk
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24313