|
|
1.1 root 1: #include "mp.h"
2:
3: mint
4: mult(a,b)
5: mint a, b;
6: {
7: mint z;
8: mint c;
9: mint mtemp;
10: int sign;
11: double a3, a2, a1, a0;
12: double b1, b0;
13: double temp1, temp2;
14:
15: if((a.high==0) && (b.high==0)){
16: c.high = 0.;
17: c.low = a.low * b.low;
18: if((c.low<e16) && (c.low > -e16)){
19: return(c);
20: }
21: }
22:
23: sign = 1;
24:
25: if((a.high<0) || (a.low<0)){
26: sign = -sign;
27: a.high = -a.high;
28: a.low = -a.low;
29: }
30: if((b.high<0) || (b.low<0)){
31: sign = -sign;
32: b.high = -b.high;
33: b.low = -b.low;
34: }
35: if(b.high != 0){
36: mtemp = a;
37: a = b;
38: b = mtemp;
39: }
40: if(b.high!=0) ofl("mult");
41:
42: modf(a.low/1e8 , &a1);
43: a0 = a.low - a1*1e8;
44: modf(b.low/1e8 , &b1);
45: b0 = b.low - b1*1e8;
46:
47: modf(a.high/1e8 , &a3);
48: a2 = a.high - a3*1e8;
49:
50: temp1 = a0*b1 + a1*b0;
51: modf(temp1/1e8 , &temp2);
52: z.low = a0*b0 + (temp1 - temp2*1e8)*1e8;
53: z.high = a1*b1 + a2*b0 + (a2*b1 + a3*b0)*1e8 + temp2;
54: while(z.low >= e16){
55: z.low = z.low - e16;
56: z.high = z.high + 1.;
57: }
58: if(z.high >= e16)
59: ofl("mult");
60: if(a3*b1!= 0)
61: ofl("mult");
62:
63: if(sign<0){
64: z.high = -z.high;
65: z.low = -z.low;
66: }
67: return(z);
68: }
69:
70: mint
71: smult(a,b)
72: mint a;
73: int b;
74: {
75: return(mult(a, itom(b)));
76: }
77: ofl(s)
78: char *s;
79: {
80: printf("%s: overflow\n",s);
81: abort();
82: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.