/* ** Pascal Sebah : July 1999 ** ** Subject: ** ** A very easy program to compute sqrt(2) with many digits. ** No optimisations, no tricks, just a basic program to learn how ** to compute in multiprecision. ** ** Formula: ** ** sqrt(2) = (239/169)*1/sqrt(1-1/57122) ** ** Data: ** ** A big real (or multiprecision real) is defined in base B as: ** X = x(0) + x(1)/B^1 + ... + x(n-1)/B^(n-1) ** where 0<=x(i) #include long B=10000; /* Working base */ long LB=4; /* Log10(base) */ /* ** Set the big real x to the small integer Integer */ void SetToInteger (long n, long *x, long Integer) { long i; for (i=1; i=0; i--) { x[i] += y[i]+carry; if (x[i]=0; i--) { xi = x[i]*q; xi += carry; if (xi>=B) { carry = xi/B; xi -= (carry*B); } else carry = 0; x[i] = xi; } } /* ** Division of the big real x by the integer d ** Like school division with carry management */ void Div (long n, long *x, long d) { long carry=0, xi, q, i; for (i=0; i