The man page for "nextafter" and "nextafterf" states that they will signal overflow and underflow if the result is not a normalized number (and I believe they should signal "inexact" as well, based on section F.9.8.3 of ISO/IEC 9899:TC2, the "C99" standard.) On an X8664 architecture with the -m64 option the functions do so, but with the -m32 option they do not. I reproduced this on various versions of Fedora Core OS with both gcc 3 and gcc 4, so it appears to be a longstanding problem: -bash-3.1$ cat csjc.c #include <stdio.h> #include <math.h> #include <fenv.h> int main(int argc, char **argv) { float x, s, y; * ((unsigned *) &x) = 0x00800000; s = 0.0; feclearexcept(FE_ALL_EXCEPT); y = nextafterf(x, s); unsigned i = fetestexcept(FE_ALL_EXCEPT); printf("nextafterf: %x\n", * ((unsigned *) &y)); printf("fetestexcept: %x\n", i); printf("FE_UNDERFLOW: %x\n", FE_UNDERFLOW); printf("FE_INEXACT: %x\n", FE_INEXACT); return 0; } -bash-3.1$ gcc -v -save-temps -o csjc.m32 -m32 csjc.c -lm Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux Thread model: posix gcc version 4.1.1 20060525 (Red Hat 4.1.1-1) /usr/libexec/gcc/x86_64-redhat-linux/4.1.1/cc1 -E -quiet -v csjc.c -m32 -mtune=generic -fpch-preprocess -o csjc.i ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.1.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.1.1/include /usr/include End of search list. /usr/libexec/gcc/x86_64-redhat-linux/4.1.1/cc1 -fpreprocessed csjc.i -quiet -dumpbase csjc.c -m32 -mtune=generic -auxbase csjc -version -o csjc.s GNU C version 4.1.1 20060525 (Red Hat 4.1.1-1) (x86_64-redhat-linux) compiled by GNU C version 4.1.1 20060525 (Red Hat 4.1.1-1). GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 990baec469b77ffbcfce8c2c8d27c0bf as -V -Qy --32 -o csjc.o csjc.s GNU assembler version 2.16.91.0.6 (x86_64-redhat-linux) using BFD version 2.16.91.0.6 20060212 /usr/libexec/gcc/x86_64-redhat-linux/4.1.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o csjc.m32 /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../lib/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../lib/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.1.1/32/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.1.1/32 -L/usr/lib/gcc/x86_64-redhat-linux/4.1.1/32 -L/usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../lib -L/lib/../lib -L/usr/lib/../lib csjc.o -lm -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.1.1/32/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../lib/crtn.o -bash-3.1$ gcc -o csjc.m64 -m64 csjc.c -lm -bash-3.1$ ./csjc.m32 nextafterf: 7fffff fetestexcept: 0 FE_UNDERFLOW: 10 FE_INEXACT: 20 -bash-3.1$ ./csjc.m64 nextafterf: 7fffff fetestexcept: 30 FE_UNDERFLOW: 10 FE_INEXACT: 20
http://sources.redhat.com/ml/libc-hacker/2007-03/msg00038.html
Subject: Bug 3306 CVSROOT: /cvs/glibc Module name: libc Branch: glibc-2_5-branch Changes by: jakub@sourceware.org 2007-07-12 15:08:18 Modified files: . : ChangeLog math : bug-nextafter.c bug-nexttoward.c math_private.h s_nextafter.c s_nexttowardf.c sysdeps/i386/fpu: s_nextafterl.c s_nexttoward.c s_nexttowardf.c sysdeps/ieee754/flt-32: s_nextafterf.c sysdeps/ieee754/ldbl-128: s_nextafterl.c s_nexttoward.c sysdeps/ieee754/ldbl-128ibm: s_nextafterl.c s_nexttoward.c s_nexttowardf.c sysdeps/ieee754/ldbl-96: s_nextafterl.c s_nexttoward.c s_nexttowardf.c sysdeps/ieee754/ldbl-opt: s_nexttowardfd.c Added files: sysdeps/i386/fpu: math_private.h sysdeps/x86_64/fpu: math_private.h Log message: 2007-04-01 Jakub Jelinek <jakub@redhat.com> * sysdeps/ieee754/ldbl-128ibm/s_nextafterl.c (__nextafterl): Use math_opt_barrier and math_force_eval macros. 2007-03-27 Jakub Jelinek <jakub@redhat.com> [BZ #3306] * math/math_private.h (math_opt_barrier, math_force_eval): Define. * sysdeps/i386/fpu/math_private.h: New file. * sysdeps/x86_64/fpu/math_private.h: New file. * math/s_nexttowardf.c (__nexttowardf): Use math_opt_barrier and math_force_eval macros. Use "+m" constraint on asm rather than "=m" and "m". * math/s_nextafter.c (__nextafter): Likewise. * sysdeps/ieee754/ldbl-128ibm/s_nexttoward.c (__nexttoward): Likewise. * sysdeps/ieee754/flt-32/s_nextafterf.c (__nextafterf): Likewise. * sysdeps/ieee754/ldbl-128/s_nexttoward.c (__nexttoward): Likewise. * sysdeps/ieee754/ldbl-96/s_nexttoward.c (__nexttoward): Likewise. * sysdeps/i386/fpu/s_nextafterl.c (__nextafterl): Use math_opt_barrier and math_force_eval macros. * sysdeps/ieee754/ldbl-128/s_nextafterl.c (__nextafterl): Likewise. * sysdeps/ieee754/ldbl-96/s_nextafterl.c (__nextafterl): Likewise. * sysdeps/i386/fpu/s_nexttoward.c: Include float.h. (__nexttoward): Use math_opt_barrier and math_force_eval macros. Use "+m" constraint on asm rather than "=m" and "m". Only use asm to force double result if FLT_EVAL_METHOD is 2. * sysdeps/i386/fpu/s_nexttowardf.c: Include float.h. (__nexttowardf): Use math_opt_barrier and math_force_eval macros. Use "+m" constraint on asm rather than "=m" and "m". Only use asm to force double result if FLT_EVAL_METHOD is not 0. * sysdeps/ieee754/ldbl-128ibm/s_nexttowardf.c: Include float.h. (__nexttowardf): Use math_opt_barrier and math_force_eval macros. If FLT_EVAL_METHOD is not 0, force x to float using asm. * sysdeps/ieee754/ldbl-opt/s_nexttowardfd.c: Include float.h. (__nldbl_nexttowardf): Use math_opt_barrier and math_force_eval macros. If FLT_EVAL_METHOD is not 0, force x to float using asm. * sysdeps/ieee754/ldbl-96/s_nexttowardf.c: Include float.h. (__nexttowardf): Use math_opt_barrier and math_force_eval macros. If FLT_EVAL_METHOD is not 0, force x to float using asm. * math/bug-nextafter.c (zero, inf): New variables. (main): Add new tests. * math/bug-nexttoward.c (zero, inf): New variables. (main): Add new tests. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/libc/ChangeLog.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.10362.2.60&r2=1.10362.2.61 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/math/bug-nextafter.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.3&r2=1.3.8.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/math/bug-nexttoward.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.1&r2=1.1.8.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/math/math_private.h.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.20&r2=1.20.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/math/s_nextafter.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.1&r2=1.1.4.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/math/s_nexttowardf.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.1&r2=1.1.4.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/i386/fpu/math_private.h.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=NONE&r2=1.1.6.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/i386/fpu/s_nextafterl.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.11&r2=1.11.8.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/i386/fpu/s_nexttoward.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.2&r2=1.2.8.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/i386/fpu/s_nexttowardf.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.2&r2=1.2.8.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/ieee754/flt-32/s_nextafterf.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.3&r2=1.3.8.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/ieee754/ldbl-128/s_nextafterl.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.1&r2=1.1.10.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/ieee754/ldbl-128/s_nexttoward.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.3&r2=1.3.8.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/ieee754/ldbl-128ibm/s_nextafterl.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.1&r2=1.1.4.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/ieee754/ldbl-128ibm/s_nexttoward.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.1&r2=1.1.4.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/ieee754/ldbl-128ibm/s_nexttowardf.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.1&r2=1.1.4.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/ieee754/ldbl-96/s_nextafterl.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.3&r2=1.3.10.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/ieee754/ldbl-96/s_nexttoward.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.6&r2=1.6.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/ieee754/ldbl-96/s_nexttowardf.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.2&r2=1.2.10.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/ieee754/ldbl-opt/s_nexttowardfd.c.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=1.1&r2=1.1.4.1 http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/x86_64/fpu/math_private.h.diff?cvsroot=glibc&only_with_tag=glibc-2_5-branch&r1=NONE&r2=1.1.6.1
One filed has been missed in this commit, causing failures in the testsuite on s390 when built with gcc 4.3: sysdeps/ieee754/ldbl-128/s_nexttowardf.c
Created attachment 2721 [details] Patch to fix the problem.
Any news on that?
It appears the final case of this was fixed by the commit: commit 64f388285e11812f041d3aa8347f82efde4033c1 Author: Jakub Jelinek <jakub@redhat.com> Date: Sat Jan 16 17:55:37 2010 -0800 sysdeps/ieee754/ldbl-128/ fixes (the rest having been fixed in 2007).