Re: Signed division with rounding towards -infinity (and floating point rounding)

2007-09-19 Thread Jim Wilson
Christopher Key wrote: The most concise form that I've found so far is: const int d = 8; // 16, 32 etc x = y / d - ((y % d < 0) ? 1 : 0) although this still produces rather longer code (see example below). Any integer divide by constant can be replaced by a sequence of multiply, shift, and add

Re: Signed division with rounding towards -infinity (and floating point rounding)

2007-09-18 Thread Christopher Key
Tim Prince wrote: > Christopher Key wrote: > > >> I have some code that needs to perform signed division by a power of two >> with rounding towards minus infinity, i.e. it requires an arithmetic >> right shift. Now in the C specification, right shifting a signed >> integer is implementation def

Re: Signed division with rounding towards -infinity (and floating point rounding)

2007-09-18 Thread Tim Prince
Christopher Key wrote: > I have some code that needs to perform signed division by a power of two > with rounding towards minus infinity, i.e. it requires an arithmetic > right shift. Now in the C specification, right shifting a signed > integer is implementation defined. Because C may be compil

Signed division with rounding towards -infinity (and floating point rounding)

2007-09-18 Thread Christopher Key
Hello, Apologies if this has already been covered; I've searched the archives and not found anything. I have some code that needs to perform signed division by a power of two with rounding towards minus infinity, i.e. it requires an arithmetic right shift. Now in the C specification, right shift