On 7/12/2010 3:15 PM, osmium wrote:
> Billy Mays wrote:
>
>> On 7/12/2010 1:54 PM, Vincenzo Mercuri wrote:
>>>
>>> or simply:
>>>
>>> y = (y - 1) / h * h; 
>>>
>>> (you had a great idea!)
>>>
>>
>>
>> I believe this would give the same result:
>>
>> (y - 1) - (( y - 1) % h)
>>
>> but without the multiply and divide.
>
> You think % is done without division?
>
>
It can be
/************************************************** *****/
#include <stdio.h>
#include <stdint.h>
int main(int argc, char ** argv)
{
int y;
y = 31;
y = (((int64_t)(y-1) * 0x66666667LL) >> 34) ;
y = (y<<3) + (y<<1);
printf("%d\n", y);
return 0;
}
/************************************************** *****/
--
Billy Mays
http://www.jpgdump.com <- My attempt at humor.