Bug 175913 - Wrong calculation result with complex SQRT in gfortran
Wrong calculation result with complex SQRT in gfortran
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
4
i386 Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-12-16 03:01 EST by Alexander Täschner
Modified: 2007-11-30 17:11 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-12-16 08:44:28 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Alexander Täschner 2005-12-16 03:01:42 EST
The square root of -4.0 should be (0.0,2.0), but in the following
test program it gives (0.0,-2.0). For this test the following version
of gcc were used: gcc version 4.0.2 20051125 (Red Hat 4.0.2-8).

[taschna@localhost ~]$ cat ctest.f
      PROGRAM CTEST
      DOUBLE COMPLEX Z1, Z2, Z3

        Z1=(2.0d0,0.0d0)
        Z2=-Z1**2
        Z3=SQRT(Z2)

        WRITE(*,*) 'SQRT((-4.0d0,0.0d0))=', SQRT((-4.0d0,0.0d0))
        WRITE(*,*) 'Z2=', Z2
        WRITE(*,*) 'Z3=SQRT(Z2)=', Z3

      END
[taschna@localhost ~]$ gfortran -O0 ctest.f -o ctest;./ctest
 SQRT((-4.0d0,0.0d0))= (  0.00000000000000     ,  2.00000000000000     )
 Z2= ( -4.00000000000000     ,  0.00000000000000     )
 Z3=SQRT(Z2)= (  0.00000000000000     , -2.00000000000000     )


The program gives also the wrong result, when DOUBLE COMPLEX is
substituted with COMPLEX.
Comment 1 Jakub Jelinek 2005-12-16 08:44:28 EST
The result is certainly the same as with Intel Fortran 9.0
(as well as the same thing rewritten into C).
The reason is that:
Z1**2 is (4.0d0,0.0d0), but -Z1**2 is (-4.0d0,-0.0d0).
And while SQRT((-4.0d0,0.0d0)) is really (0.0d0,2.0d0), SQRT((-4.0d0,-0.0d0))
is (0.0d0,-2.0d0).
Comment 2 Alexander Täschner 2005-12-18 07:04:37 EST
This is a changed behaviour compared to g77 (3.4.4 20050721 (Red Hat 3.4.4-2)).
On Windows the Compaq Visual Fortran 6 gives also the result (0,2).
Therefore I am not sure whether it is a bug or not. I came across the bug when
testing to compile the CERNLIB. There the math test C208 failed because of
the new behaviour.

Note You need to log in before you can comment on or make changes to this bug.