This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Round-to-even without modifying rounding mode?
- From: Matt Turner <mattst88 at gmail dot com>
- To: libc-help at sourceware dot org
- Date: Thu, 5 Feb 2015 11:51:59 -0800
- Subject: Round-to-even without modifying rounding mode?
- Authentication-results: sourceware.org; auth=none
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?