Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Jun 2004 20:00:47 -0700 (PDT)
From:      David Schultz <das@FreeBSD.ORG>
To:        freebsd-standards@FreeBSD.org
Subject:   Re: standards/59797: Implement C99's round[f]() math fucntions
Message-ID:  <200406050300.i5530loM044235@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR standards/59797; it has been noted by GNATS.

From: David Schultz <das@FreeBSD.ORG>
To: "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, freebsd-standards@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.



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