1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)msqrt.c	5.1 (Berkeley) 4/30/85";
   9: #endif not lint
  10: 
  11: #include <mp.h>
  12: msqrt(a,b,r) MINT *a,*b,*r;
  13: {   MINT x,junk,y;
  14:     int j;
  15:     x.len=junk.len=y.len=0;
  16:     if(a->len<0) fatal("msqrt: neg arg");
  17:     if(a->len==0)
  18:     {   b->len=0;
  19:         r->len=0;
  20:         return(0);
  21:     }
  22:     if(a->len%2==1) x.len=(1+a->len)/2;
  23:     else x.len=1+a->len/2;
  24:     x.val=xalloc(x.len,"msqrt");
  25:     for(j=0;j<x.len;x.val[j++]=0);
  26:     if(a->len%2==1) x.val[x.len-1]=0400;
  27:     else x.val[x.len-1]=1;
  28:     xfree(b);
  29:     xfree(r);
  30: loop:
  31:     mdiv(a,&x,&y,&junk);
  32:     xfree(&junk);
  33:     madd(&x,&y,&y);
  34:     sdiv(&y,2,&y,(short *)&j);
  35:     if(mcmp(&x,&y)>0)
  36:     {   xfree(&x);
  37:         move(&y,&x);
  38:         xfree(&y);
  39:         goto loop;
  40:     }
  41:     xfree(&y);
  42:     move(&x,b);
  43:     mult(&x,&x,&x);
  44:     msub(a,&x,r);
  45:     xfree(&x);
  46:     return(r->len);
  47: }

Defined functions

msqrt defined in line 12; never used

Defined variables

sccsid defined in line 8; never used
Last modified: 1987-02-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2321
Valid CSS Valid XHTML 1.0 Strict