|strength redcution firstname.lastname@example.org (Vespasian) (2005-04-30)|
|Re: strength redcution Danny.Dube@ift.ulaval.ca (2005-05-01)|
|Re: strength redcution email@example.com (glen herrmannsfeldt) (2005-05-01)|
|From:||glen herrmannsfeldt <firstname.lastname@example.org>|
|Date:||1 May 2005 09:24:53 -0400|
|Posted-Date:||01 May 2005 09:24:53 EDT|
Danny Dubé wrote:
> Vespasian <email@example.com> writes:
>>Anyone know how to replace the expression,
>>i div c,
>>with addition and/or subtraction, where c in a constant and
>>i is the index of a loop that increments with a step size of 1
>>[Seems to me you'd have to keep a separate counter and each time
This sounds a little bit like that phase accumulator sometimes
used for generating digitized sine waves from a lookup table.
I table of sin(x) evaluated at some binary fraction of a complete
circle, maybe 256ths of a circle is used. One might want a sine wave
where the frequency isn't a multiple of 1/256th of the sample rate.
Adding an appropriate constant to a larger accumulator, maybe 32 bits,
and then using the high bits with the lookup table generates the result
that over the long term has the appropriate periodicity, given
sufficient bits in the accumulator.
To get back to the subject of compilers, I believe that many now
replace fixed point division by a constant with multiplication and
shifting in many cases. It does still seem strange to me, without
testing to make sure the result agrees. Even for floating point
one would want the correctly rounded or truncated result.
Return to the
Search the comp.compilers archives again.