Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Dec 2003 20:09:39 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
Cc:        freebsd-standards@freebsd.org
Subject:   Re: fenv.h implementation questions
Message-ID:  <20031224200114.F5421@gamplex.bde.org>
In-Reply-To: <200312240600.hBO606TJ066756@troutmask.apl.washington.edu>
References:  <200312240600.hBO606TJ066756@troutmask.apl.washington.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 23 Dec 2003, Steven G. Kargl wrote:

> Bruce Evans wrote:
> > On Sun, 21 Dec 2003, Steven G. Kargl wrote:
> >
> > > Is the following a sufficient implementation of fenv.h?
> > > _fenv_t and _fexcept_t would be defined in machine/fenv.h,
> > > which I haven't implemented, yet.  I'm assuming that
> > > these may be architecture specific (e.g., endianness).
> >
> > fenv_t and fexcept_t are very MD, and hopefully aren't needed
> > in more than 1 file, so they should be declared directly in
> > <machine/fenv.h>.
>
> Certainly, fenv_t and fexcept_t are MD, but I don't
> believe that their use is restricted to 1 file (unless
> I'm totally misinterpreting what you wrote).  Consider,

I checked.  It is only defined in <fenv.h> according to C99 (n869.txt
draft) and and POSIX.1-2001 (draft7).

> #include <errno.h>
> #include <fenv.h>
> #include <math.h>
>
> int foo(x) {
>    double x;
>    fexcept_t bar;
>    errno = 0;
>    x = ceil(x);
>    if (errno != 0) { /* FE occurred */
>       fegetexception(&bar, FE_ALL_EXCEPT);
>       /* Do something to address FE */
>    } else {
>      ....
>    }
> }

You got it from <fenv.h> there.  It is not in <math.h> though.

> (snip)
>
> > > #ifdef _EXCEPTIONS
> > > #define FE_DIVBYZERO	0x00000001	/* Divide by zero */
> > > #define FE_INEXACT	0x00000002	/* Inexact flag raised */
> > > #define FE_INVALID	0x00000004	/* Invalid operation */
> > > #define FE_OVERFLOW	0x00000008	/* Overflow */
> > > #define FE_UNDERFLOW	0x00000010	/* Underflow */
> > > #define FE_ALL_EXCEPT	0x0000001F	/* Bitwise-or of above flags */
> > > #endif /* _EXCEPTIONS */
> > >
> > > #ifdef _ROUNDING_MODES
> > > #define FE_DOWNWARD	0x00000020	/* Round downward */
> > > #define FE_TONEAREST	0x00000040	/* Round to nearest */
> > > #define FE_TOWARDZERO	0x00000080	/* Round towards zero */
> > > #define FE_UPWARD	0x00000100	/* Round upwards */
> > > #endif /* _ROUNDING_MODES */
> >
> > These should probably all be MD.  It saves a negative amount of code to
> > use a common definition since larger code would be required to convert
> > between the MI bits and the MI bits.
> >
>
> I'll have to look at SuSv3 again, but the above definitions
> should be suitable for both big and little endian machines.
> I'm not sure about 32 bit versus 64 bit machines.  Are you
> concerned that an architecture may only support a subset of
> the above flags?

Each arch has its own natural definitions of the flags.  E.g., on i386's
the natural division by 0 flag is FP_X_DZ = 0x04, not 0x00000001.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031224200114.F5421>