The following produces an FPE when compiled with -ffpe-trap=invalid: real :: x = 1.0 print *, sqrt(-1.0*x) However, using acos or asin does not: real :: x = 1.0 print *, acos(5.0*x) print *, asin(5.0*x) Instead it just prints out "NaN". The FPE is missing both in 4.3 and on trunk.
What target? Works for me on FreeBSD. laptop:kargl[23] ~/work/bin/gfortran -static -o z -ffpe-trap=invalid j.f90 laptop:kargl[24] ./z Floating exception (core dumped) laptop:kargl[25] cat j.f90 real :: x = 1.0 print *, acos(5.0*x) print *, asin(5.0*x) end
Sorry, forgot to specify the target: x86_64-unknown-linux-gnu.
Confirm: Here, I get the same result with -m64 on Linux (NaN and no SIGFPE), but with -m32 (with both -mfpmath=sse and -mfpmath=387) I get the SIGFPE. The FPE settings are used in libgfortran/config/*; maybe fpu-387.h does something wrong in the x86-64 mode?
Or maybe libc's acos is broken .... In which case this is not a GCC bug.
Also on i386-apple-darwin9.6.0 the FPEs are thrown correctly.
On x86_64-unknown-linux-gnu I *do* get the ICE when I compile with -ffast-math -mfpmath=387. Cf. http://gcc.gnu.org/ml/fortran/2008-11/msg00250.html.
Note that the problem also appears for log, while it does not for acosh and atanh: real :: x = -5.0 ! FPE is not thrown print *, log(x) print *, log10(x) print *, acos(x) print *, asin(x) ! FPE is thrown !print *, sqrt(x) !print *, atanh(x) !print *, acosh(x) end
> Note that the problem also appears for log, while it does not for acosh and > atanh: If it works with some but not all libm routines, it sounds more like a GLIBC than like a GCC problem.
(In reply to comment #8) > If it works with some but not all libm routines, it sounds more like a GLIBC > than like a GCC problem. Can someone reproduce this with C code?
> Can someone reproduce this with C code? Yes: The following gives a SIGFPE with -m32 (logf, sqrtf) and with -m64 and "sqrtf" but not with -m64 with "logf". (Compile with "-fsignaling-nans" and "-lm".) -----------------<cut>-------------------- #ifndef __SUPPORT_SNAN__ # error No SNAN support - use "-fsignaling-nans" #endif #define _WANT_SNAN 1 #include <stdio.h> #include <math.h> #include <fenv.h> int main() { float x = -5.0, y; feenableexcept(FE_ALL_EXCEPT); y = logf(x); printf("%e\n",y); return 0; }
The x86_64 FPE code in libgfortran works fine, as evidenced by the fact that it works with some glibcs (RedHat's glibc-2.5 for example) and on Mac OS 10.5.6 (which uses the same FPE setter). Closing as INVALID, please report to glibc or distro vendor (Tobias did it with Novell here: https://bugzilla.novell.com/show_bug.cgi?id=487576)
On #gcc it was confirmed to give a SIGFPE on gentoo with glibc 2.9 on x86-64. I think it is one of the @amd.com patches for x86-64 which fixes some performance problems but has the side effect that it doesn't honour the FPE.