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."

2 of 279 comments (clear)

  1. RIAA Rounding by ackthpt · · Score: 0, Flamebait

    RIAA method:
    if (sales(type_cd,2005) < sales(type_cd,2004)) {
    set_sales(type_cd,2005)=0;
    blame_pirates();
    }

    --

    A feeling of having made the same mistake before: Deja Foobar
  2. Add and truncate by RackinFrackin · · Score: 1, Flamebait

    When I need to implement rounding, I add .5 and then truncate. I believe (perhaps naively) that this is efficient because of the lack of branching.