From: Charles R H. <cha...@gm...> - 2006-09-04 16:32:55
|
On 9/4/06, Paulo J. S. Silva <pjs...@im...> wrote: > > Interesting, I was just reading about the round rule in IEEE standard > last Friday. > > What numpy's "around" function does is called "round to even" (round is > take to make the next digit even), instead of "round up". According to > "What every computer scientist should know about floating-point > arithmetic" (do a Google search), the reason to prefer "round to even" > is exemplified by the following result from Reiser and Knuth: > > Theorem > > Let x and y be floating-point numbers, and define x0 = x, x1 = (x0 - y) > + y, ..., xn = (xn-1 - y) + y. If + and - are exactly rounded using > round to even, then either xn = x for all n or xn = x1 for all n >= 1. > > If you use "round up" the sequence xn can start increasing slowly "for > ever", and as the paper says: > > "...This example suggests that when using the round up rule, > computations can gradually drift upward, whereas when using round to > even the theorem says this cannot happen." > > Best, > > Paulo However, around does set the sign bit when rounding -.5 to zero: >>> around(-.5).tostring() '\x00\x00\x00\x00\x00\x00\x00\x80' so that >>> around(-.5) -0.0 on the other hand >>> around(-.5) == 0.0 True I didn't know -0.0 was part of the IEEE spec. Chuck |