This is the mail archive of the
mailing list for the glibc project.
Re: Round-to-even without modifying rounding mode?
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Mike Frysinger <vapier at gentoo dot org>
- Cc: <libc-help at sourceware dot org>
- Date: Mon, 2 Mar 2015 14:05:10 +0000
- Subject: Re: Round-to-even without modifying rounding mode?
- Authentication-results: sourceware.org; auth=none
- References: <CAEdQ38GAjVaVJ9b=BqyOpUiZJbB-QYvVT=mN=uQGZw668Me+jw at mail dot gmail dot com> <20150302063417 dot GY19363 at vapier>
On Mon, 2 Mar 2015, Mike Frysinger wrote:
> On 05 Feb 2015 11:51, Matt Turner wrote:
> > The rint() family of functions with the rounding mode set to
> > FE_TONEAREST is the only libc function I can find that will do
> > round-to-even. round() rounds half away from zero.
> > By setting various rounding modes rint() can do floor/ceil/trunc, but
> > there doesn't seem to be function that simply does round-to-even. Is
> > there one I've missed?
> > Alternatively, the reservations I have about setting the rounding mode
> > come from vague ideas about high costs involved with doing so and
> > potential problems from changing the rounding mode in a library. Are
> > either of these concerns valid, or should I simply save and restore
> > the rounding mode around a call to rint() to get round-to-even
> > behavior?
> adding Joseph as i'm not sure he's subscribed to this group
You want roundeven in TS 18661-1:2014 (note that's equivalent to nearbyint
not rint - it's specified not to raise "inexact", as are
round/floor/ceil/trunc in TS 18661-1:2014; see bug 15479).
I'm not aware of any current plans for implementing TS 18661-1 support in
The rounding mode is thread-local. Saving and restoring it around a
function call should be fine.
Joseph S. Myers