Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1511 Incorrect computation with complex numbers

closed-fixed
Cesar Strauss
gcc (462)
2011-10-12
2011-01-24
Abel K
No

gcc -std=c99 complexbug3.c -o complexbug3.exe & complexbug3
(0.2 - I*0.3)*(0.3 - I*0.9) = (0.06, -0.09)

gcc complexbug3.c -o complexbug3.exe & complexbug3
(0.2 - I*0.3)*(0.3 - I*0.9) = (-0.21, -0.27)

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/program files/mingw/bin/../libexec/gcc/mingw32/4.5.0/lto-
wrapper.exe
Target: mingw32
Configured with: ../gcc-4.5.0/configure --enable-languages=c,c++,ada,fortran,obj
c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo
mp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-r
untime-libs --disable-werror --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.5.0 (GCC)

ld -v
GNU ld (GNU Binutils) 2.20.51.20100613

ver
Microsoft Windows [Version 5.2.3790]

Discussion

  • Abel K
    Abel K
    2011-01-24

    complexbug3.c

     
    Attachments
  • Keith Marshall
    Keith Marshall
    2011-01-24

    • milestone: --> 772667
    • status: open --> pending-invalid
     
  • Keith Marshall
    Keith Marshall
    2011-01-24

    Sorry, but I don't understand what you think the problem is here; (+0.2 * +0.3 = +0.06) + ((i * i = -1) * -0.3 * -0.3 = -0.27) = +0.21; (+0.2 * -0.9i = -0.18i) + (0.3 * -0.3i = -0.09i) = -0.27i; that result looks completely correct to me.

     
  • Keith Marshall
    Keith Marshall
    2011-01-25

    • milestone: 772667 -->
    • assigned_to: nobody --> cstrauss
    • status: pending-invalid --> open
     
  • Keith Marshall
    Keith Marshall
    2011-01-25

    I'm sorry; I completely missed the first result in your original report, on first reading. Clearly *that* result is incorrect.

    FWIW, I am not able to reproduce this with GCC-3.4.5, (my Linux hosted mingw32-gcc cross-compiler), nor with the native GCC-4.4.5 on the Linux host itself. However, I *am* able to reproduce it with the latest MinGW GCC-4.5.2 on Windows-Vista, so perhaps this is a regression in the GCC-4.5 series.

    Unless Cesar has some alternative idea, I guess you need to report this upstream, to the GCC maintainers directly.

     

  • Anonymous
    2011-01-27

    may be worth noting, gcc guys have applied patch on gcc upstream trunk

     
  • Cesar Strauss
    Cesar Strauss
    2011-10-12

    • status: open --> closed-fixed
     
  • Cesar Strauss
    Cesar Strauss
    2011-10-12

    Seems to be fixed in the latest release (4.6.1).

    $ gcc -std=c99 complexbug3.c -o complexbug3.exe && ./complexbug3
    (0.2 - I*0.3)*(0.3 - I*0.9) = (-0.21, -0.27)

    $ gcc complexbug3.c -o complexbug3.exe && complexbug3
    (0.2 - I*0.3)*(0.3 - I*0.9) = (-0.21, -0.27)

    Thanks,
    Cesar