In many respects, life seemed to be a whole lot simpler when I was a young lad. Take the subject of rounding, for example. If we wanted to round a value like 6.1, 6.2, 6.3, or 6.4 to the nearest whole number, then the answer was 6. Similarly, if we wanted to round 6.6, 6.7, 6.8, or 6.9 to the nearest whole number, then the answer was 7. The only tricky one was the “half-way” value of 6.5, but our teachers told us to round this up to 7, so that’s what we did. “Easy peasy lemon squeezy,” as it were. At that time, I honestly thought that this was all there was to know about rounding. Ah… I was so young, so trusting, and so foolish in those far off days of yore. I’m much wiser (and sadder) now. Over the years, I was introduced to different flavors of rounding, but it wasn’t until I started work on the book How Computers Do Math that I delved deeper into this topic, at which time I discovered how little I knew.
Summary of different rounding algorithms (Click image to see a larger version — Image source: Max Maxfield)
Seriously, most people wouldn’t believe the variety of rounding algorithms that can be employed by different applications. These include round-toward-nearest, round-half-up (arithmetic rounding), round-half-down, round-half-even (banker’s rounding), round-half-odd, round-ceiling (toward positive infinity), round-floor (toward negative-infinity), round-toward-zero, round-away-from-zero, round-up, round-down, truncation (chopping), round-alternate, and round-random (stochastic rounding). Things really get interesting when you start to think about rounding signed binary values, and don’t even start me talking about symmetric versus asymmetric implementations. A big problem is that, even if you understand all this stuff, you really need to pay attention when you are designing hardware or developing software, because different applications may treat things differently. For example, the round method of the Java Math Library provides an asymmetric implementation of the round-half-up algorithm, while the round function in the mathematical modeling, simulation, and visualization tool MATLAB from The MathWorks provides a symmetric implementation. Furthermore, just for giggles and grins, the round function in Visual Basic for Applications 6.0 actually implements the round-half-even (banker’s rounding) algorithm. If you are interested in learning more about all of this, may I be so bold as to point you at my Introduction to Rounding Algorithms, which explains everything in excruciating detail accompanied by lots of lovingly hand-crafted graphics. Also, it may not surprise you to hear that those clever chaps and chappesses at OmniCalculator.com (with 897 free calculators the last time I looked) provide a handy-dandy Rounding Calculator for us to play with:
Rounding Numbers Calculator
The reason I’m waffling on about rounding here is that my chum Jay Dowling just sent me a link to a rather interesting article on The Deadly Consequences of Rounding Errors, which explains how in politics, stock markets, space, and on the battlefield, tiny software calculation mistakes have had enormous consequences. How about you? Have you ever run into a situation where rounding errors caused problems, or where a software application was using a different rounding technique to the one you were expecting?