Implementing C99's roundf(), round(), and roundl()

Bruce Evans bde at zeta.org.au
Mon Dec 1 14:57:42 PST 2003


On Mon, 1 Dec 2003, Steve Kargl wrote:

> On Mon, Dec 01, 2003 at 07:05:18PM +1100, Bruce Evans wrote:
> > All the other corner cases need to be checked.  It's possibly to check
> > all 2^32 cases for floats (once you know the correct results).
>
> Do you have code to do this check?
>
> > Other things to check: setting of exception flags.  I'm not sure if the
> > settings by ceil() are the right ones and the only ones.

I thought of a good way after righting the above: roundf() is supposed to
be equivalent to rintf() with certain rounding, so set the rounding mode
and call rintf() to determine the correct value.  Unfortunately there
might not be a correct rounding mode (what does round to nearest do
for integers?  I think it rounds to even, but roundf() requires rounding
up half-way cases).

> AFAICT, we can't do the exception handling according to POSIX, because
> we don't have <fenv.h>, feclearexcept(), and fetestexcept() implemented,
> yet.

RIght, but we have fpgetsticky(), etc.

Bruce


More information about the freebsd-standards mailing list