[mkgmap-dev] Rounding bug in splitter?
From Marko Mäkelä marko.makela at iki.fi on Tue Aug 11 06:56:58 BST 2009
On Mon, Aug 10, 2009 at 09:37:44PM +0000, Chris Miller wrote: > Assuming my understanding above is correct, here's how I think the rounding > methods should be implemented to give the correct rounding in all situations: > > private int roundDown(int val) { > return val >> SHIFT << SHIFT; > } I would write this as return val & ~(1 << SHIFT); > private int roundUp(int val) { > return (val + (1 << SHIFT) - 1) >> SHIFT << SHIFT; > } And this one as return (val + ((1 << SHIFT) - 1))) & ~(1 << SHIFT); It's probably not a big deal, but if SHIFT is a compile-time constant and the compiler performs constant folding, the run-time code should be shorter and faster. Marko
- Previous message: [mkgmap-dev] Rounding bug in splitter?
- Next message: [mkgmap-dev] Rounding bug in splitter?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the mkgmap-dev mailing list