Bug 175913 - Wrong calculation result with complex SQRT in gfortran
Summary: Wrong calculation result with complex SQRT in gfortran
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 4
Hardware: i386
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2005-12-16 08:01 UTC by Alexander Täschner
Modified: 2007-11-30 22:11 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2005-12-16 13:44:28 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Alexander Täschner 2005-12-16 08:01:42 UTC
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 13:44:28 UTC
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 12:04:37 UTC
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.