Re: Floating point exceptions: how to mask & set to zero w/ no error

Malcolm Beattie (mbeattie@sable.ox.ac.uk)
Fri, 12 Apr 1996 08:58:47 +0100 (BST)


ulmo@q.net writes:
>
> Excuse my Unix & floating point ignorance please, but I'd like to
> generate some form of compatability with Speak Free (see
> ftp://ftp.fourmilab.ch/pub/kelvin/speakfree/unix/prior-releases/p/sf61a2.tar.gz
> ), the main author John Walker <kelvin@fourmilab.ch> said:
>
> > If the original PARC LPC code (which remains in the program,
> > as it is a standard VAT and RTP compression mode) is generating
> > floating point errors, this indicates that your system is not
> > masking floating point exceptions and handling them by default.
> > The LPC code routinely generates floating underflows, which the
> > FPU should set to zero with no error indication.

Do
#include <fpu_control.h>
and then
__setfpucw(_FPU_IEEE);

You guessed right that the default setting (with your kernel) is set
up to generate exceptions on underflow (and a few other things).
Setting the FPU control word to IEEE behaviour as shown above will
mask those exceptions as you wanted. Somewhere in the 1.3.x kernel
series, the default (for i386 but not m68k, it seems) changed to IEEE
behaviour anyway, so you may want to remove the explicit setting when
you upgrade. If you want more fine-grained control, see
<i386/fpu_control.h> (or <m68k/fpu_control.h> but I doubt you're
using that ;-) for gory details.

--Malcolm

-- 
Malcolm Beattie <mbeattie@sable.ox.ac.uk>
Unix Systems Programmer
Oxford University Computing Services