piclist 2017\09\06\163936a >
Thread: Division routines.
www.piclist.com/techref/microchip/math/index.htm?key=division
picon face BY : Walter Banks email (remove spam text)




On 2017-09-06 2:05 PM, smplx wrote:
{Quote hidden}

Quite correct. Optimization is throw all the code you don't need and no
more.
moral. don't post untested code.

//
// divide x/y and return an _Fract
// x < y always
//
// reference in 16 bits
//

uint16_t div_fract (uint16_t x,y)
  {
    char count = 16 ; // size of result in bits
    uint16_t result = 0;
    do
     {
      x <<= 1;
      result <<= 1;
      if (x >= y)
       {
         x -= y;
         result |= 1;
       }
     }
    while(--count);
   return result;
  }

>
> On a mid range PIC the "(x >= y)" would need to be performed as
> "(x - y >= 0)" so why not compute "x = x - y" and compare with 0?
That is essentially my compiler does.
>
> Regards
> Sergio Masci
>
>

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
mailman.mit.edu/mailman/listinfo/piclist
<f6aa56a3-0465-bf7b-eac3-eca465ad2ae5@bytecraft.com> base64

In reply to: <alpine.LNX.2.00.1709061856350.25052@tin.allotrope.net>
See also: www.piclist.com/techref/microchip/math/index.htm?key=division
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Division routines.

month overview.

new search...