Slashdot Mirror


Rounding Algorithms

dtmos writes "Clive Maxfield has an interesting article up on PL DesignLine cataloging most (all?) of the known rounding algorithms used in computer math. As he states, "...the mind soon boggles at the variety and intricacies of the rounding algorithms that may be used for different applications ... round-up, round-down, round-toward-nearest, arithmetic rounding, round-half-up, round-half-down, round-half-even, round-half-odd, round-toward-zero, round-away-from-zero, round-ceiling, round-floor, truncation (chopping), round-alternate, and round-random (stochastic rounding), to name but a few." It's a good read, especially if you *think* you know what your programs are doing."

1 of 279 comments (clear)

  1. Re:Most important... by slothman32 · · Score: 5, Informative

    There's some straight line algorithm that uses a similar method.
    It keeps adding the slope value for every x increment and when it overloads it also makes the y position go up one.
    Or something like that. Bresenham's I believe.

    To get on topic I would use the usual "(x).5 to (x+1).499~9 goes to (x+1)" way.
    For negative, just ignore the sign when doing it, e.g. -1.6 -> -2

    --
    Why don't you guys have friends or journals?