source: node_modules/robust-predicates/esm/util.js@ a762898

Last change on this file since a762898 was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[e4c61dd]1export const epsilon = 1.1102230246251565e-16;
2export const splitter = 134217729;
3export const resulterrbound = (3 + 8 * epsilon) * epsilon;
4
5// fast_expansion_sum_zeroelim routine from oritinal code
6export function sum(elen, e, flen, f, h) {
7 let Q, Qnew, hh, bvirt;
8 let enow = e[0];
9 let fnow = f[0];
10 let eindex = 0;
11 let findex = 0;
12 if ((fnow > enow) === (fnow > -enow)) {
13 Q = enow;
14 enow = e[++eindex];
15 } else {
16 Q = fnow;
17 fnow = f[++findex];
18 }
19 let hindex = 0;
20 if (eindex < elen && findex < flen) {
21 if ((fnow > enow) === (fnow > -enow)) {
22 Qnew = enow + Q;
23 hh = Q - (Qnew - enow);
24 enow = e[++eindex];
25 } else {
26 Qnew = fnow + Q;
27 hh = Q - (Qnew - fnow);
28 fnow = f[++findex];
29 }
30 Q = Qnew;
31 if (hh !== 0) {
32 h[hindex++] = hh;
33 }
34 while (eindex < elen && findex < flen) {
35 if ((fnow > enow) === (fnow > -enow)) {
36 Qnew = Q + enow;
37 bvirt = Qnew - Q;
38 hh = Q - (Qnew - bvirt) + (enow - bvirt);
39 enow = e[++eindex];
40 } else {
41 Qnew = Q + fnow;
42 bvirt = Qnew - Q;
43 hh = Q - (Qnew - bvirt) + (fnow - bvirt);
44 fnow = f[++findex];
45 }
46 Q = Qnew;
47 if (hh !== 0) {
48 h[hindex++] = hh;
49 }
50 }
51 }
52 while (eindex < elen) {
53 Qnew = Q + enow;
54 bvirt = Qnew - Q;
55 hh = Q - (Qnew - bvirt) + (enow - bvirt);
56 enow = e[++eindex];
57 Q = Qnew;
58 if (hh !== 0) {
59 h[hindex++] = hh;
60 }
61 }
62 while (findex < flen) {
63 Qnew = Q + fnow;
64 bvirt = Qnew - Q;
65 hh = Q - (Qnew - bvirt) + (fnow - bvirt);
66 fnow = f[++findex];
67 Q = Qnew;
68 if (hh !== 0) {
69 h[hindex++] = hh;
70 }
71 }
72 if (Q !== 0 || hindex === 0) {
73 h[hindex++] = Q;
74 }
75 return hindex;
76}
77
78export function sum_three(alen, a, blen, b, clen, c, tmp, out) {
79 return sum(sum(alen, a, blen, b, tmp), tmp, clen, c, out);
80}
81
82// scale_expansion_zeroelim routine from oritinal code
83export function scale(elen, e, b, h) {
84 let Q, sum, hh, product1, product0;
85 let bvirt, c, ahi, alo, bhi, blo;
86
87 c = splitter * b;
88 bhi = c - (c - b);
89 blo = b - bhi;
90 let enow = e[0];
91 Q = enow * b;
92 c = splitter * enow;
93 ahi = c - (c - enow);
94 alo = enow - ahi;
95 hh = alo * blo - (Q - ahi * bhi - alo * bhi - ahi * blo);
96 let hindex = 0;
97 if (hh !== 0) {
98 h[hindex++] = hh;
99 }
100 for (let i = 1; i < elen; i++) {
101 enow = e[i];
102 product1 = enow * b;
103 c = splitter * enow;
104 ahi = c - (c - enow);
105 alo = enow - ahi;
106 product0 = alo * blo - (product1 - ahi * bhi - alo * bhi - ahi * blo);
107 sum = Q + product0;
108 bvirt = sum - Q;
109 hh = Q - (sum - bvirt) + (product0 - bvirt);
110 if (hh !== 0) {
111 h[hindex++] = hh;
112 }
113 Q = product1 + sum;
114 hh = sum - (Q - product1);
115 if (hh !== 0) {
116 h[hindex++] = hh;
117 }
118 }
119 if (Q !== 0 || hindex === 0) {
120 h[hindex++] = Q;
121 }
122 return hindex;
123}
124
125export function negate(elen, e) {
126 for (let i = 0; i < elen; i++) e[i] = -e[i];
127 return elen;
128}
129
130export function estimate(elen, e) {
131 let Q = e[0];
132 for (let i = 1; i < elen; i++) Q += e[i];
133 return Q;
134}
135
136export function vec(n) {
137 return new Float64Array(n);
138}
Note: See TracBrowser for help on using the repository browser.