piclist 2017\09\07\131644a >
Thread: Division routines.
www.piclist.com/techref/microchip/math/index.htm?key=division
flavicon
face BY : smplx email (remove spam text)





On Thu, 7 Sep 2017, David C Brown wrote:

> The basic non restoring algorithm must have been developed by Turing or
> Wilkes or one of there contemporaries back in the fifties.   For interest,
> or not, This my take on it. - 55 memories, 2 working registers,  worst case
> 156 instructions.  Please criticise to your hearts content

I belive you meen something like the following:

int frac_div(int x, int y)
{
       int        res;

       res  = 0;

       x -= y;

       for (int j=16; j>0; j--)
       {
               res <<= 1;

               if ((x & 0x8000) != 0)
               {
                       // x < 0  i.e. x is < y

                       // x = (x - y) * 2
                       // i.e. x = (x * 2) - (y * 2)
                       x <<= 1;

                       // x = (x * 2) - (y * 2) + y
                       // i.e. x = (x * 2) - y
                       x += y;
               }
               else
               {
                       // x >= 0 i.e. x >= y

                       // x = x * 2
                       x <<= 1;

                       // x = (x * 2) - y
                       x -= y;

                       res |= 1;
               }
       }

       return res;
}

I misunderstood. From your original post I thought you were having difficulty forming a fraction from two integers.

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
.

<alpine.LNX.2.00.1709071913110.32537@tin.allotrope.net> quoted-printable

In reply to: <CAFo_nNrZHRfMnVUVEnhM+JFytmdiOUh+B4=yFcP42Ye51a9=0A@mail.gmail.com>
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...