From owner-freebsd-questions Tue Aug 18 09:02:22 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id JAA09080 for freebsd-questions-outgoing; Tue, 18 Aug 1998 09:02:22 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from base486.home.org (imdave.pr.mcs.net [205.164.3.77]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id JAA09073 for ; Tue, 18 Aug 1998 09:02:16 -0700 (PDT) (envelope-from imdave@mcs.net) Received: (from imdave@localhost) by base486.home.org (8.8.8/8.8.8) id LAA12892; Tue, 18 Aug 1998 11:01:10 -0500 (CDT) Date: Tue, 18 Aug 1998 11:01:10 -0500 (CDT) From: Dave Bodenstab Message-Id: <199808181601.LAA12892@base486.home.org> To: freebsd-questions@FreeBSD.ORG, griepent@wias-berlin.de Subject: Re: Floating point exceptions on i386 and FreeBSD-2.2.X Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 #include #include 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