This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Round-to-even without modifying rounding mode?


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 
glibc.

The rounding mode is thread-local.  Saving and restoring it around a 
function call should be fine.

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]