Re: 32 bit fixed point division



>#include <stdint.h>
>
>uint64_t Divide32(uint32_t y, uint32_t x)
>{
> uint16_t n;
> uint64_t answer;
> uint64_t remainder;
> uint64_t divisor;
>
> answer = 0;
> remainder = x;
> divisor = (uint64_t)y << 32;
>
> for (n = 0; n < 32; n++)
> {
> divisor = divisor >> 1;
> if (remainder >= divisor)
> {
> remainder -= divisor;
> answer |= (uint64_t)1 << (63 - n);
> }
> }
>
> for (n = 0; n < 32; n++)
> {
> remainder = remainder << 1;
> if (remainder >= divisor)
> {
> remainder -= divisor;
> answer |= (uint64_t)1 << (31 - n);
> }
> }
>
> return answer;
>}
>
>

Hi Randy,
Thank you very much for this wonderful code. It minimised my problem to a
great extent.

Thanks again,

Regards
bd.


This message was sent using the Comp.DSP web interface on
www.DSPRelated.com
.



Relevant Pages

  • Re: Dividing 512 bit number by 128 bit number in C program
    ... calculating the quotient and the remainder before returning. ... In one of the inner loops, the divisor is positioned so that its most ... A bit-wise subtraction of divisor from dividend is performed ... bool borrow = false; ...
    (sci.crypt)
  • Re: Sign conventions for remainder
    ... What about if both the divisor and the dividend are negative? ... > If the divisor is positive, the remainder should still be in the range ... options in your package for the several possible sensible behaviours. ...
    (sci.math)
  • Re: How to perform integer div with SIMD?
    ... First, use the approximate reciprocal lookup to generate a set of starting values, then one or two NR iterations (also in SIMD fp mode) to get a more precise value. ... If negative, subtract one from the result, add divisor to remainder. ...
    (comp.lang.asm.x86)
  • Re: fixed point division in 32 bits
    ... i got some clue from a code posted by you. ... uint64_t remainder; ... uint64_t divisor; ... is your input data limited in magnitude? ...
    (comp.dsp)
  • Re: Sign conventions for remainder
    ... Addition, subtraction, and multiplication ... > the conventions for remainders. ... What about if both the divisor and the dividend are negative? ... the remainder should still be in the range ...
    (sci.math)