[E-Lang] Operators #6: Multiplicative operators

Ben Laurie ben@algroup.co.uk
Wed, 25 Apr 2001 17:33:15 +0100


"Mark S. Miller" wrote:
> 
> At 10:29 AM Monday 4/23/01, Ben Laurie wrote:
> >"Mark S. Miller" wrote:
> >> I believe in the IEEE context, "round to nearest" actually means "round to
> >> even".
> >
> >I don't understand what you mean by that - but 1 should round up, of
> >course (for the same reason 5 does in decimal).
> 
> I believe the IEEE "round to even" means: when there's an unambiguous
> nearest, take that.  When, the true value is exactly half way between the
> representable values, choose the representable value whose low order bit is
> 0 rather than 1.  So, using your decimal analogy:
> 
>     1.5  rounds to  2
>     2.5  rounds to  2
>     3.5  rounds to  4
> 
> I take no stance on whether this is a good idea.  It's mandated by IEEE and
> inherited by Java, so it's what we've got.

Good Lord! I had no idea!

BTW, the maths argument is that you are looking at the interval [0,1)
which divides equally into [0,.5) and [.5,1), so .5 is actually "nearer"
to 1 than 0 (by 1/infinity). Hence .5 always rounds up. Rounding down
would imply the division [0,.5] and (.5,1), which differ by two points.

For those not familiar with the notation, [] include the endpoint, and
() exclude it.

I presume the IEEE method gives better accuracy in practice (unless
using infinite precision :-).

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html

"There is no limit to what a man can do or how far he can go if he
doesn't mind who gets the credit." - Robert Woodruff

ApacheCon 2001! http://ApacheCon.com/