Here's is a simple J illustration how round-half-up is accumulating deviation compared to round-to-even method: as we shall see, by the order of magnitude. Stochastic method behaves similarly to round-to-even.

For a set of 1000 numbers.

   N=. 0.1 * 1000 ?.@$ 100
   ] S1=. +/N                      NB. exact sum
4888.7
   ] S2=. +/<.N+0.5                NB. round-half-up
4948
   ] S3=. +/<.N+0.5+_0.1*2|<.N     NB. round-to-even
4898
   ] S4=. +/<.N+0.5+_0.1*2?.@$~#N  NB. stochastic
4898
   S1%~|S1-S2
0.01213
   S1%~|S1-S3
0.00190235
   S1%~|S1-S4
0.00190235

For a set of 10000 numbers.

   N=. 0.1 * 10000 ?.@$ 100
   ] S1=. +/N                      NB. exact sum
49477.5
   ] S2=. +/<.N+0.5                NB. round-half-up
50030
   ] S3=. +/<.N+0.5+_0.1*2|<.N     NB. round-to-even
49531
   ] S4=. +/<.N+0.5+_0.1*2?.@$~#N  NB. stochastic
49536
   S1%~|S1-S2
0.0111667
   S1%~|S1-S3
0.0010813
   S1%~|S1-S4
0.00118236

See Also

OlegKobchenko/Rounding (last edited 2009-03-31 08:16:12 by OlegKobchenko)