25 May 2013 07:03
Rounding Floats : Beware
General erlang point, rather than CB-specific, but . . .
I made a casual google search on erlang rounding and turned up the following:
"round/1 returns the closest integer to x, rounding to even when x is halfway between two integers."
(TrapExit http://www.trapexit.org/Floating_Point_Rounding - though the error is repeated in several other places)
NOT TRUE ( well not on my system anyway)I made a casual google search on erlang rounding and turned up the following:
"round/1 returns the closest integer to x, rounding to even when x is halfway between two integers."
(TrapExit http://www.trapexit.org/Floating_Point_Rounding - though the error is repeated in several other places)
ROUND HALF TO EVEN is a very common standard practice, particularly in bookkeeping applications (and according to Wikipedia, "This is the default rounding mode used in IEEE 754 computing functions and operators").
However, erlang uses ROUND HALF AWAY FROM ZERO.
From my shell:
(eg <at> testhost)12> round (3.5).
4
(eg <at> testhost)13> round (4.5).
5
(eg <at> testhost)14> round(-3.5).
-4
(eg <at> testhost)15> round(-4.5).
-5
(eg <at> testhost)16>
This may catch some by surprise - it certainly did me. It happens that for this application neither is what I need (I want ROUND HALF UP, but that is a different story).
Dont believe all you readgraeme
PS
(With my generous hat on . . . Perhaps the behaviour was different in the past.
)You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
RSS Feed