standards/59797: Implement C99's round[f]() math fucntions
David Schultz
das at FreeBSD.ORG
Sat Jun 5 03:01:11 GMT 2004
The following reply was made to PR standards/59797; it has been noted by GNATS.
From: David Schultz <das at FreeBSD.ORG>
To: "Steven G. Kargl" <kargl at troutmask.apl.washington.edu>
Cc: FreeBSD-gnats-submit at FreeBSD.ORG, freebsd-standards at FreeBSD.ORG
Subject: Re: standards/59797: Implement C99's round[f]() math fucntions
Date: Fri, 4 Jun 2004 19:53:59 -0700
Sorry, I've put this off way too long. The good news is that I'm
now going to do something about it. The bad news is that I found
a significant bug in the proposed implementation. Namely, round()
and roundf() often get the wrong answer for halfway cases. In
IEEE-754 round-to-nearest mode, numbers that are halfway between
two representable numbers are supposed to be rounded to even. For
instance, 0.5 becomes 0, and 1.5 becomes 2. I don't see an easy
way to make this work in the present implementation without
fiddling with the underlying bits. Perhaps we need to implement
it more similarly to fdlibm's rint().
BTW, benchmarking shows that using the sample implementation that
appears in the C99 standard results in a slowdown of two orders of
magnitude over your round() implementation and four orders of
magnitude over the x87 frndint instruction. Just setting the
rounding mode and calling rint() also results in a significant
slowdown. Thus, we definitely want something that's in the spirit
of what you wrote, but perhaps one that operates on the bits directly.
More information about the freebsd-standards
mailing list