Date: Sat, 07 Nov 1998 10:35:44 -0600 From: Dave Bodenstab <imdave@mcs.net> To: Phillip White <philw@webmaster.com> Cc: FreeBSD Questions <freebsd-questions@FreeBSD.ORG> Subject: Re: FPU - Any known issues? Message-ID: <364476E0.F5FD462@mcs.net> References: <4.1.19981106172324.00b4e530@server.webmaster.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Phillip White wrote: > > I'm running an app that pukes with SIG 8 claiming there was a floating > point exception error. Funnily enough though - this same app runs with no > problem on my BSDi 4.0 and Linux RedHat boxes. If there are any known > issues in 3.0-RELEASE environment 3.0-CURRENT kernel please forward! > This has been convered in the past. Search the archives for more info. Here is a message I posted the last time I saw this issue come up (See: http://www.freebsd.org/cgi/getmsg.cgi?fetch=642373+645610+/usr/local/www/db/text/1998/freebsd-questions/19980816.freebsd-questions From: griepent@wias-berlin.de > > But there occur so much serious floating point exceptions and > strange underflows! Can I trust any longer the libm of FreeBSD? > Most of my programs written in C use the Mesa library. > They run very well on other architectures like Alpha machines with DEC Unix, > Silicons with Irix and also i386 machines with Linux. > Using the same compiler gcc-2.7.2.1 under FreeBSD-2.2.X I had > always to compile libm, Mesa-2.6 libraries and my own programs > without any optimization flags to get partially executable code! This subject has been discussed in the past... The reason that Linux gives no exceptions is that the floating point exceptions are *masked* by default. The default for FreeBSD, on the other hand, is that floating point exceptions are *unmasked*. Therefore, what you are seeing is that the software you run under Linux does a poor job of dealing with numerical precision -- the programs simply ignores any errors. In some cases this is OK -- Intel's NPX applies reasonable defaults for floating point exceptions. > It is a pity but sticking to Linux seems to be the only way > for me to get reliable numerical results. To get the same results with FreeBSD, you need to modify the programs to set the exception mask yourself. Try the following program: ----- #include <stdio.h> #include <math.h> #include <floatingpoint.h> main( int argc, char **argv ) { double a, b; /* * Mask all exceptions if argc > 1 */ if ( argc > 1 ) fpsetmask( ~ (FP_X_INV | FP_X_DNML | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP) ); a = 1.0; b = cos(0.0) - 1.0; a /= b; /* * This used to be necessary to avoid a kernel message ``pid %d (%s) * exited with masked floating point exceptions 0x%02x''. The kernel * now wraps this message with ``#ifdef NPX_DEBUG'' */ fpresetsticky( FP_X_INV | FP_X_DNML | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP ); } ----- bash$ cc fpx.c -lm bash$ ./a.out Floating point exception (core dumped) bash$ ./a.out no bash$ Dave Bodenstab imdave@mcs.net To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?364476E0.F5FD462>