This is the mail archive of the libc-alpha@sources.redhat.com 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]

Re: [rfc] rint() rounds to even


Ben Collins wrote on 2001-01-29 16:31 UTC:
> I have a bug report which I am not sure is a bug or a feature that is
> just misunderstood. The rint() function appears to round towards even
> numbers. IOW, rint(1.5) and rint(2.5) both return "2.0", aswell
> rint(3.5) and rint(4.5) both return "4.0".
> 
> Now my math may be a little rusty and old, but I always assumed that
> "n.5" always rounded to "n+1". Is this not the case for standard math
> functions? If so, is this documented somewhere?

ISO 31-0:1992(E) "Quantities and units -- General Principles" Annex B
(informative) "Guide to rounding numbers" says:

------------------------------------------------------------------

[...]

B.3  If there are two successive integral multiples equally near a given
number, two different rules are in use.

Rule A: The even integral multiple is selected as the rounded number.

Rule B: The higher integral multiple is selected as the rounded number.

Note 25: Rule A is generally preferable and of special advantage when
treating, for example, series of measurements in such a way that the
rounding error is minimized.

Rule B is widely used in computers.

[...]

------------------------------------------------------------------

I learned about both rules in high school and was told that rounding to
an even last digit in the border case makes a statistical bias
introduced by rounding slightly less likely. Sounded reasonable to me.

Hope this helped ...

Markus

-- 
Markus G. Kuhn, Computer Laboratory, University of Cambridge, UK
Email: mkuhn at acm.org,  WWW: <http://www.cl.cam.ac.uk/~mgk25/>


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