Menu

#2337 sqrt(-1) does not return NAN

OTHER
closed
nobody
None
Bug
invalid
Unknown
False
2017-02-01
2017-02-01
Daniel WEIL
No

With the cross-compiler i686-w64-mingw32-gcc.exe, on PentiumI7 with Windows10, the sqrt function returns identity instead of NaN.
To reproduce the bug:

  • on a Pentium I7 with windows10 (tried with recent DELL XPS13)
    *- install cygwin with the i686-w64-mingw32-gcc.exe cross-compiler
  • compiler the attached file
$ i686-w64-mingw32-gcc.exe -o essai essai.c -v && ./essai
Utilisation des specs internes.
COLLECT_GCC=i686-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/5.4.0/lto-wrapper.exe
Cible : i686-w64-mingw32
Configuré avec: /cygdrive/i/szsz/tmpp/cygwin64/mingw64-i686/mingw64-i686-gcc-5.4                               .0-3.i686/src/gcc-5.4.0/configure --srcdir=/cygdrive/i/szsz/tmpp/cygwin64/mingw6                               4-i686/mingw64-i686-gcc-5.4.0-3.i686/src/gcc-5.4.0 --prefix=/usr --exec-prefix=/                               usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/mingw64-i686-                               gcc --htmldir=/usr/share/doc/mingw64-i686-gcc/html -C --build=i686-pc-cygwin --h                               ost=i686-pc-cygwin --target=i686-w64-mingw32 --without-libiconv-prefix --without                               -libintl-prefix --with-sysroot=/usr/i686-w64-mingw32/sys-root --with-build-sysro                               ot=/usr/i686-w64-mingw32/sys-root --disable-multilib --disable-win32-registry --                               enable-languages=c,ada,c++,fortran,lto,objc,obj-c++ --enable-fully-dynamic-strin                               g --enable-graphite --enable-libgomp --enable-libquadmath --enable-libquadmath-s                               upport --enable-libssp --enable-version-specific-runtime-libs --with-dwarf2 --wi                               th-gnu-ld --with-gnu-as --with-tune=generic --with-cloog-include=/usr/include/cl                               oog-isl --with-system-zlib --enable-threads=posix --libexecdir=/usr/lib
Modèle de thread: posix
gcc version 5.4.0 (GCC)
COLLECT_GCC_OPTIONS='-o' 'essai.exe' '-v' '-mtune=generic' '-march=pentiumpro'
 /usr/lib/gcc/i686-w64-mingw32/5.4.0/cc1.exe -quiet -v -D_REENTRANT essai.c -qui                               et -dumpbase essai.c -mtune=generic -march=pentiumpro -auxbase essai -version -o                                /tmp/ccbqPl1C.s
GNU C11 (GCC) version 5.4.0 (i686-w64-mingw32)
        compilé par GNU C version 5.4.0, GMP version 6.1.0, MPFR version 3.1.4,                                MPC version 1.0.3
warning: GMP header version 6.1.0 differs from library version 6.1.2.
warning: MPFR header version 3.1.4 differs from library version 3.1.5.
heuristiques GGC: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
le répertoire « /usr/i686-w64-mingw32/sys-root/usr/local/include » est ignoré ca                               r inexistant
le répertoire « /usr/lib/gcc/i686-w64-mingw32/5.4.0/../../../../i686-w64-mingw32                               /include » est ignoré car inexistant
la recherche pour #include "..." débute ici :
la recherche pour #include <...> débute ici:
 /usr/lib/gcc/i686-w64-mingw32/5.4.0/include
 /usr/lib/gcc/i686-w64-mingw32/5.4.0/include-fixed
 /usr/i686-w64-mingw32/sys-root/mingw/include
Fin de la liste de recherche.
GNU C11 (GCC) version 5.4.0 (i686-w64-mingw32)
        compilé par GNU C version 5.4.0, GMP version 6.1.0, MPFR version 3.1.4,                                MPC version 1.0.3
warning: GMP header version 6.1.0 differs from library version 6.1.2.
warning: MPFR header version 3.1.4 differs from library version 3.1.5.
heuristiques GGC: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 94288b9bd2212c08d70115a290bc41ca
COLLECT_GCC_OPTIONS='-o' 'essai.exe' '-v' '-mtune=generic' '-march=pentiumpro'
 /usr/lib/gcc/i686-w64-mingw32/5.4.0/../../../../i686-w64-mingw32/bin/as.exe -v                                -o /tmp/ccDzZTqz.o /tmp/ccbqPl1C.s
Version de l'assembleur GNU 2.25.51 (i686-w64-mingw32) utilisant la version BFD                                (GNU Binutils) 2.25.51.20150320
COMPILER_PATH=/usr/lib/gcc/i686-w64-mingw32/5.4.0/:/usr/lib/gcc/i686-w64-mingw32                               /5.4.0/:/usr/lib/gcc/i686-w64-mingw32/:/usr/lib/gcc/i686-w64-mingw32/5.4.0/:/usr                               /lib/gcc/i686-w64-mingw32/:/usr/lib/gcc/i686-w64-mingw32/5.4.0/../../../../i686-                               w64-mingw32/bin/
LIBRARY_PATH=/usr/lib/gcc/i686-w64-mingw32/5.4.0/:/usr/lib/gcc/i686-w64-mingw32/                               5.4.0/../../../../i686-w64-mingw32/lib/../lib/:/usr/i686-w64-mingw32/sys-root/mi                               ngw/lib/../lib/:/usr/lib/gcc/i686-w64-mingw32/5.4.0/../../../../i686-w64-mingw32                               /lib/:/usr/i686-w64-mingw32/sys-root/mingw/lib/
COLLECT_GCC_OPTIONS='-o' 'essai.exe' '-v' '-mtune=generic' '-march=pentiumpro'
 /usr/lib/gcc/i686-w64-mingw32/5.4.0/collect2.exe -plugin /usr/lib/gcc/i686-w64-                               mingw32/5.4.0/cyglto_plugin-0.dll -plugin-opt=/usr/lib/gcc/i686-w64-mingw32/5.4.                               0/lto-wrapper.exe -plugin-opt=-fresolution=/tmp/ccYN2qLl.res -plugin-opt=-pass-t                               hrough=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc                               _eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -pl                               ugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lpthread -plugin-opt=                               -pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-t                               hrough=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-                               lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plu                               gin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt                               =-pass-through=-lmsvcrt --sysroot=/usr/i686-w64-mingw32/sys-root -m i386pe -Bdyn                               amic -o essai.exe /usr/i686-w64-mingw32/sys-root/mingw/lib/../lib/crt2.o /usr/li                               b/gcc/i686-w64-mingw32/5.4.0/crtbegin.o -L/usr/lib/gcc/i686-w64-mingw32/5.4.0 -L                               /usr/lib/gcc/i686-w64-mingw32/5.4.0/../../../../i686-w64-mingw32/lib/../lib -L/u                               sr/i686-w64-mingw32/sys-root/mingw/lib/../lib -L/usr/lib/gcc/i686-w64-mingw32/5.                               4.0/../../../../i686-w64-mingw32/lib -L/usr/i686-w64-mingw32/sys-root/mingw/lib                                /tmp/ccDzZTqz.o -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lpthread                                -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -l                               mingwex -lmsvcrt /usr/i686-w64-mingw32/sys-root/mingw/lib/../lib/default-manifes                               t.o /usr/lib/gcc/i686-w64-mingw32/5.4.0/crtend.o
sqrt(-2.000000)=-2.000000, is nan : 0
acos(-2.000000)=-1.#IND00, is nan : 1
sqrt(-1.500000)=-1.500000, is nan : 0
acos(-1.500000)=-1.#IND00, is nan : 1
sqrt(-1.000000)=-1.000000, is nan : 0
acos(-1.000000)=3.141593, is nan : 0
sqrt(-0.500000)=-0.500000, is nan : 0
acos(-0.500000)=2.094395, is nan : 0
sqrt(0.000000)=0.000000, is nan : 0
acos(0.000000)=1.570796, is nan : 0
sqrt(0.500000)=0.707107, is nan : 0
acos(0.500000)=1.047198, is nan : 0
sqrt(1.000000)=1.000000, is nan : 0
acos(1.000000)=0.000000, is nan : 0
sqrt(1.500000)=1.224745, is nan : 0
acos(1.500000)=-1.#IND00, is nan : 1
sqrt(2.000000)=1.414214, is nan : 0
acos(2.000000)=-1.#IND00, is nan : 1
  • and observe that the acos function returns NaN for absolute value above 1, but sqrt (x) returns x for negative value!!!!

The bug is processor-dependant and seems to happen only with last version of gcc.

Configuration used :

$ uname -a
CYGWIN_NT-10.0-WOW PC-Daniel-ARGOSIM 2.6.1(0.305/5/3) 2016-12-16 11:50 i686 Cygwin

Windows Config:
C:\Users\daniel>ver
Microsoft Windows [version 10.0.14393]

gcc:
$ i686-w64-mingw32-gcc.exe -v
Utilisation des specs internes.
COLLECT_GCC=i686-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/5.4.0/lto-wrapper.exe
Cible : i686-w64-mingw32
Configuré avec: /cygdrive/i/szsz/tmpp/cygwin64/mingw64-i686/mingw64-i686-gcc-5.4.0-3.i686/src/gcc-5.4.0/configure --srcdir=/cygdrive/i/szsz/tmpp/cygwin64/mingw64-i686/mingw64-i686-gcc-5.4.0-3.i686/src/gcc-5.4.0 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/mingw64-i686-gcc --htmldir=/usr/share/doc/mingw64-i686-gcc/html -C --build=i686-pc-cygwin --host=i686-pc-cygwin --target=i686-w64-mingw32 --without-libiconv-prefix --without-libintl-prefix --with-sysroot=/usr/i686-w64-mingw32/sys-root --with-build-sysroot=/usr/i686-w64-mingw32/sys-root --disable-multilib --disable-win32-registry --enable-languages=c,ada,c++,fortran,lto,objc,obj-c++ --enable-fully-dynamic-string --enable-graphite --enable-libgomp --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-version-specific-runtime-libs --with-dwarf2 --with-gnu-ld --with-gnu-as --with-tune=generic --with-cloog-include=/usr/include/cloog-isl --with-system-zlib --enable-threads=posix --libexecdir=/usr/lib
Modèle de thread: posix
gcc version 5.4.0 (GCC)
1 Attachments

Discussion

  • Daniel WEIL

    Daniel WEIL - 2017-02-01

    The problem seemed to be located into the mingw64-i686-headers and mingw64-i686-runtime
    With older versions 4.6 of these packages, no bug, with 5.0.0 or 5.0.1, mentionned bug.

     
  • Keith Marshall

    Keith Marshall - 2017-02-01
    • status: unread --> closed
    • Resolution: none --> invalid
     
  • Keith Marshall

    Keith Marshall - 2017-02-01

    There is so much wrong with this "bug" report, I barely know where to begin!

    on a Pentium I7 with windows10

    I don't have any such platform, so that sure isn't going to happen; in any case, if it's that platform specific, why should I suspect anything beyond the platform itself?

    install cygwin ...

    Not our project, so that isn't going to happen.

    ... with the i686-w64-mingw32-gcc.exe cross-compiler

    Not our product; not supported here.

    compiler the attached file

    In the context of this report, that is far too complex! You should have reduced it to something like:

    $ cat tsqrt.c
    #include <stdio.h>
    #include <tgmath.h>
    
    int main()
    { double x = sqrt( -1.0 );
      printf( "sqrt( -1.0 ) = %g; isnan reports %d\n", x, isnan( x ));
      return 0;
    }
    

    FWIW, with our compiler (GCC-5.3.0) and supporting libraries (mingwrt-3.22.4 and w32api-3.18.2), this WJFFM, both when cross-compiled and run under wine, on my Linux box:

    $ mingw32-gcc tsqrt.c
    $ ./a.exe
    sqrt( -1.0 ) = -nan; isnan reports 1
    

    and in WinXP (running in Linux hosted VM):

    $ gcc tsqrt.c
    $ ./a
    sqrt( -1.0 ) = -1.#IND; isnan reports 1
    
     

    Last edit: Keith Marshall 2017-02-01
  • Daniel WEIL

    Daniel WEIL - 2017-02-01

    Thanks for your answer. After more investigation, it appears that the bug is not specific to a processor and windows version but related to the version of the following packages : mingw64-i686-headers and mingw64-i686-runtime.

    With older versions 4.6 of these packages, no bug
    With 5.0.0 or 5.0.1, mentionned bug.

    Can you reproduce the bug with such configuration ?

     
    • Keith Marshall

      Keith Marshall - 2017-02-01

      I have no interest in even trying. Those packages do not originate from our project (MinGW.org); why would you possibly expect us to support (possibly broken) products emanating from a completely unrelated project?

       
  • Daniel WEIL

    Daniel WEIL - 2017-02-01

    Sorry to bother you but I'm going on in my investigation.

    To summarize, the bug is not related to cygwin, nor any cross-compilation, but ** to the last version 5.4 of the gcc mingw compiler**.

    First I simplified my example (file sqrtNan.c)

    #include <stdio.h>
    #include <math.h>
    int main(){
      double x = -2.0;
      printf("sqrt(%f)=%f, is nan : %d\n", x, sqrt(x), isnan(sqrt(x)));
      printf("acos(%f)=%f, is nan : %d\n", x, acos(x), isnan(acos(x)));
    

    Then, to eliminate cygwin or cross-compilation, I installed directly on my computer 2 version of gcc.

    $ gcc sqrtNan.c -o sqrtNan.exe -v >& gcc5.3.log
    
    daniel@PC-Daniel-ARGOSIM ~/dev/xxx/Stimulus/src
    $ ./sqrtNan.exe
    sqrt(-2.000000)=-1.#IND00, is nan : 1
    acos(-2.000000)=-1.#IND00, is nan : 1
    

    gcc5.4 installed from https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/5.4.0/threads-win32/sjlj/i686-5.4.0-release-win32-sjlj-rt_v5-rev0.7z : KO

    $ gcc sqrtNan.c -o sqrtNan.exe -v >& gcc5.4.log
    
    daniel@PC-Daniel-ARGOSIM ~/dev/xxx/Stimulus/src
    $ ./sqrtNan.exe
    sqrt(-2.000000)=-2.000000, is nan : 0
    acos(-2.000000)=-1.#IND00, is nan : -1
    

    This make it clear that the bug has appeared with version 5.4 of the mingw port of gcc. Can you tell me if the bug is of the responsability of your project or if I should report to the gcc project ?
    (I already loggued it, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79320, but I've been told that it's more probably a ming issue).

     
  • Daniel WEIL

    Daniel WEIL - 2017-02-01

    Sorry to have taken your time : I just mistake your project with the mingw-w64 project and found my bug was already logged : https://sourceforge.net/p/mingw-w64/bugs/567/ !

    So you can delete the ticket!!

     

    Last edit: Daniel WEIL 2017-02-01
  • Keith Marshall

    Keith Marshall - 2017-02-01
    • discussion: enabled --> disabled
     
  • Keith Marshall

    Keith Marshall - 2017-02-01

    You are pursuing it in entirely the wrong forum! The compiler tools, header files, and libraries you are using are in no way related to any product distributed by, or in any way related to, or supported by the MinGW.org Project. Quite simply: your findings are of no use or interest to this project; posting them here will not bring them to the attention of anyone who will either care, or be able to take any action to resolve your issues.

    Please find the proper bug tracker for posting your findings; this most definitely is not it. If you post any more of this irrelevant rubbish here, I will delete the entire ticket.