http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49031
Summary: powl() function gives wrong results in some situations Product: gcc Version: 4.5.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other AssignedTo: unassig...@gcc.gnu.org ReportedBy: eliasrudb...@gmail.com Created attachment 24270 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24270 The powlbug.i file generated by "gcc -v -save-temps -lm powlbug.c". Hello! There seems to be a bug in the powl() function in the gcc -lm library, as shown by the following test program: $ cat powlbug.c #include <stdio.h> #include <math.h> #include <string.h> int main() { long double xx = 1e-20; printf("xx = %12.6Lg\n", xx); printf("powl(xx, 1.5) = %12.6Lg\n", powl(xx, 1.5)); if(1) { long double a = 0.2; long double b; char chararr_b[16] = {1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16, 63}; memcpy(&b, chararr_b, 16); printf("powl(a, b) = %9.4Lg\n", powl(a, b)); } printf("powl(xx, 1.5) = %12.6Lg\n", powl(xx, 1.5)); return 0; } $ gcc -lm powlbug.c $ ./a.out xx = 1e-20 powl(xx, 1.5) = 1e-30 powl(a, b) = 1 powl(xx, 1.5) = 0.353553 Since xx is set to 1e-20, the result of powl(xx, 1.5) should always be 1e-30. It seems like the powl(a, b) call messes up something inside the math library, so that the following call powl(xx, 1.5) gives 0.353553 which is very wrong. If I change if(1) to if(0) the second call to powl(xx, 1.5) gives 1e-30 as it should. $ gcc --version gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4) $ gcc -v -save-temps -lm powlbug.c Using built-in specs. COLLECT_GCC=/usr/bin/gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.5.1/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,lto --enable-plugin --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64' /usr/libexec/gcc/x86_64-redhat-linux/4.5.1/cc1 -E -quiet -v powlbug.c -mtune=generic -march=x86-64 -fpch-preprocess -o powlbug.i ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.5.1/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib/gcc/x86_64-redhat-linux/4.5.1/include /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64' /usr/libexec/gcc/x86_64-redhat-linux/4.5.1/cc1 -fpreprocessed powlbug.i -quiet -dumpbase powlbug.c -mtune=generic -march=x86-64 -auxbase powlbug -version -o powlbug.s GNU C (GCC) version 4.5.1 20100924 (Red Hat 4.5.1-4) (x86_64-redhat-linux) compiled by GNU C version 4.5.1 20100924 (Red Hat 4.5.1-4), GMP version 4.3.1, MPFR version 2.4.2, MPC version 0.8.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C (GCC) version 4.5.1 20100924 (Red Hat 4.5.1-4) (x86_64-redhat-linux) compiled by GNU C version 4.5.1 20100924 (Red Hat 4.5.1-4), GMP version 4.3.1, MPFR version 2.4.2, MPC version 0.8.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: ea394b69293dd698607206e8e43d607e COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64' as -V -Qy --64 -o powlbug.o powlbug.s GNU assembler version 2.20.51.0.7 (x86_64-redhat-linux) using BFD version version 2.20.51.0.7-6.fc14 20100318 COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.5.1/:/usr/libexec/gcc/x86_64-redhat-linux/4.5.1/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.5.1/:/usr/lib/gcc/x86_64-redhat-linux/ LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.5.1/:/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64' /usr/libexec/gcc/x86_64-redhat-linux/4.5.1/collect2 --build-id --no-add-needed --eh-frame-hdr -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.5.1/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.5.1 -L/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../.. -lm powlbug.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.5.1/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../lib64/crtn.o The powlbug.i file generated by "gcc -v -save-temps -lm powlbug.c" is attached. / Elias