SPUG:strange rounding problems
AEH at akc.org
Thu Jan 30 17:19:44 CST 2003
I believe IEEE floating point specifications support four different
This one ("round toward even") is the default.
It's definately not unique to perl - C's printf rounds this way on my
(1) I goofed below: 15.5 -> 16.
(2) this method trades bias toward infinity for bias toward even
numbers, which isn't always a good thing.
(3) it's important to note that while 15.5 could be rounded to 15 or 16
depending on your rounding method, 15.50001 should always round to 16
and 15.49999 should always round to 15.
(assuming we're rounding to zero decimal places).
(4) Somebody mentioned it being hardware/OS dependent...If so, I guess
perl doesn't specify IEEE fp arithmetic conformance ?
>>> Alan <alan at ufies.org> 01/30/03 05:33PM >>>
Is this just the way that perl does it, or is this something that I
wasn't taught in school?
On Thu, Jan 30, 2003 at 05:24:01PM -0500, Adrian Hands wrote:
> Odd rounds up, even rounds down.
> 11.5 -> 12
> 12.5 -> 12
> 13.5 -> 14
> 14.5 -> 14
> 15.5 -> 15
> This prevents skewing in favor of up.
More information about the spug-list