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 _______________________________________________ mkgmap-dev mailing list mkgmap-dev@lists.mkgmap.org.uk http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev