1: /*	@(#)msqrt.c	4.1	12/25/82	*/
   2: 
   3: #include <mp.h>
   4: msqrt(a,b,r) MINT *a,*b,*r;
   5: {   MINT x,junk,y;
   6:     int j;
   7:     x.len=junk.len=y.len=0;
   8:     if(a->len<0) fatal("msqrt: neg arg");
   9:     if(a->len==0)
  10:     {   b->len=0;
  11:         r->len=0;
  12:         return(0);
  13:     }
  14:     if(a->len%2==1) x.len=(1+a->len)/2;
  15:     else x.len=1+a->len/2;
  16:     x.val=xalloc(x.len,"msqrt");
  17:     for(j=0;j<x.len;x.val[j++]=0);
  18:     if(a->len%2==1) x.val[x.len-1]=0400;
  19:     else x.val[x.len-1]=1;
  20:     xfree(b);
  21:     xfree(r);
  22: loop:
  23:     mdiv(a,&x,&y,&junk);
  24:     xfree(&junk);
  25:     madd(&x,&y,&y);
  26:     sdiv(&y,2,&y,(short *)&j);
  27:     if(mcmp(&x,&y)>0)
  28:     {   xfree(&x);
  29:         move(&y,&x);
  30:         xfree(&y);
  31:         goto loop;
  32:     }
  33:     xfree(&y);
  34:     move(&x,b);
  35:     mult(&x,&x,&x);
  36:     msub(a,&x,r);
  37:     xfree(&x);
  38:     return(r->len);
  39: }

Defined functions

msqrt defined in line 4; never used
Last modified: 1983-07-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 709
Valid CSS Valid XHTML 1.0 Strict