Debian Codegraph @

debian/external_deps/fetk/gamer/src/tetgen/src_c/predicates.cxx

raw
1 /*****************************************************************************/
2 /* */
3 /* Routines for Arbitrary Precision Floating-point Arithmetic */
4 /* and Fast Robust Geometric Predicates */
5 /* (predicates.c) */
6 /* */
7 /* May 18, 1996 */
8 /* */
9 /* Placed in the public domain by */
10 /* Jonathan Richard Shewchuk */
11 /* School of Computer Science */
12 /* Carnegie Mellon University */
13 /* 5000 Forbes Avenue */
14 /* Pittsburgh, Pennsylvania 15213-3891 */
15 /* [email protected] */
16 /* */
17 /* This file contains C implementation of algorithms for exact addition */
18 /* and multiplication of floating-point numbers, and predicates for */
19 /* robustly performing the orientation and incircle tests used in */
20 /* computational geometry. The algorithms and underlying theory are */
21 /* described in Jonathan Richard Shewchuk. "Adaptive Precision Floating- */
22 /* Point Arithmetic and Fast Robust Geometric Predicates." Technical */
23 /* Report CMU-CS-96-140, School of Computer Science, Carnegie Mellon */
24 /* University, Pittsburgh, Pennsylvania, May 1996. (Submitted to */
25 /* Discrete & Computational Geometry.) */
26 /* */
27 /* This file, the paper listed above, and other information are available */
28 /* from the Web page http://www.cs.cmu.edu/~quake/robust.html . */
29 /* */
30 /*****************************************************************************/
31
32 /*****************************************************************************/
33 /* */
34 /* Using this code: */
35 /* */
36 /* First, read the short or long version of the paper (from the Web page */
37 /* above). */
38 /* */
39 /* Be sure to call exactinit() once, before calling any of the arithmetic */
40 /* functions or geometric predicates. Also be sure to turn on the */
41 /* optimizer when compiling this file. */
42 /* */
43 /* */
44 /* Several geometric predicates are defined. Their parameters are all */
45 /* points. Each point is an array of two or three floating-point */
46 /* numbers. The geometric predicates, described in the papers, are */
47 /* */
48 /* orient2d(pa, pb, pc) */
49 /* orient2dfast(pa, pb, pc) */
50 /* orient3d(pa, pb, pc, pd) */
51 /* orient3dfast(pa, pb, pc, pd) */
52 /* incircle(pa, pb, pc, pd) */
53 /* incirclefast(pa, pb, pc, pd) */
54 /* insphere(pa, pb, pc, pd, pe) */
55 /* inspherefast(pa, pb, pc, pd, pe) */
56 /* */
57 /* Those with suffix "fast" are approximate, non-robust versions. Those */
58 /* without the suffix are adaptive precision, robust versions. There */
59 /* are also versions with the suffices "exact" and "slow", which are */
60 /* non-adaptive, exact arithmetic versions, which I use only for timings */
61 /* in my arithmetic papers. */
62 /* */
63 /* */
64 /* An expansion is represented by an array of floating-point numbers, */
65 /* sorted from smallest to largest magnitude (possibly with interspersed */
66 /* zeros). The length of each expansion is stored as a separate integer, */
67 /* and each arithmetic function returns an integer which is the length */
68 /* of the expansion it created. */
69 /* */
70 /* Several arithmetic functions are defined. Their parameters are */
71 /* */
72 /* e, f Input expansions */
73 /* elen, flen Lengths of input expansions (must be >= 1) */
74 /* h Output expansion */
75 /* b Input scalar */
76 /* */
77 /* The arithmetic functions are */
78 /* */
79 /* grow_expansion(elen, e, b, h) */
80 /* grow_expansion_zeroelim(elen, e, b, h) */
81 /* expansion_sum(elen, e, flen, f, h) */
82 /* expansion_sum_zeroelim1(elen, e, flen, f, h) */
83 /* expansion_sum_zeroelim2(elen, e, flen, f, h) */
84 /* fast_expansion_sum(elen, e, flen, f, h) */
85 /* fast_expansion_sum_zeroelim(elen, e, flen, f, h) */
86 /* linear_expansion_sum(elen, e, flen, f, h) */
87 /* linear_expansion_sum_zeroelim(elen, e, flen, f, h) */
88 /* scale_expansion(elen, e, b, h) */
89 /* scale_expansion_zeroelim(elen, e, b, h) */
90 /* compress(elen, e, h) */
91 /* */
92 /* All of these are described in the long version of the paper; some are */
93 /* described in the short version. All return an integer that is the */
94 /* length of h. Those with suffix _zeroelim perform zero elimination, */
95 /* and are recommended over their counterparts. The procedure */
96 /* fast_expansion_sum_zeroelim() (or linear_expansion_sum_zeroelim() on */
97 /* processors that do not use the round-to-even tiebreaking rule) is */
98 /* recommended over expansion_sum_zeroelim(). Each procedure has a */
99 /* little note next to it (in the code below) that tells you whether or */
100 /* not the output expansion may be the same array as one of the input */
101 /* expansions. */
102 /* */
103 /* */
104 /* If you look around below, you'll also find macros for a bunch of */
105 /* simple unrolled arithmetic operations, and procedures for printing */
106 /* expansions (commented out because they don't work with all C */
107 /* compilers) and for generating random floating-point numbers whose */
108 /* significand bits are all random. Most of the macros have undocumented */
109 /* requirements that certain of their parameters should not be the same */
110 /* variable; for safety, better to make sure all the parameters are */
111 /* distinct variables. Feel free to send email to [email protected] if you */
112 /* have questions. */
113 /* */
114 /*****************************************************************************/
115
116 #include <stdio.h>
117 #include <stdlib.h>
118 #include <math.h>
119 #ifdef CPU86
120 #include <float.h>
121 #endif /* CPU86 */
122 #ifdef LINUX
123 #include <fpu_control.h>
124 #endif /* LINUX */
125
126 #include "tetgen.h" // Defines the symbol REAL (float or double).
127
128 /* On some machines, the exact arithmetic routines might be defeated by the */
129 /* use of internal extended precision floating-point registers. Sometimes */
130 /* this problem can be fixed by defining certain values to be volatile, */
131 /* thus forcing them to be stored to memory and rounded off. This isn't */
132 /* a great solution, though, as it slows the arithmetic down. */
133 /* */
134 /* To try this out, write "#define INEXACT volatile" below. Normally, */
135 /* however, INEXACT should be defined to be nothing. ("#define INEXACT".) */
136
137 #define INEXACT /* Nothing */
138 /* #define INEXACT volatile */
139
140 /* #define REAL double */ /* float or double */
141 #define REALPRINT doubleprint
142 #define REALRAND doublerand
143 #define NARROWRAND narrowdoublerand
144 #define UNIFORMRAND uniformdoublerand
145
146 /* Which of the following two methods of finding the absolute values is */
147 /* fastest is compiler-dependent. A few compilers can inline and optimize */
148 /* the fabs() call; but most will incur the overhead of a function call, */
149 /* which is disastrously slow. A faster way on IEEE machines might be to */
150 /* mask the appropriate bit, but that's difficult to do in C. */
151
152 #define Absolute(a) ((a) >= 0.0 ? (a) : -(a))
153 /* #define Absolute(a) fabs(a) */
154
155 /* Many of the operations are broken up into two pieces, a main part that */
156 /* performs an approximate operation, and a "tail" that computes the */
157 /* roundoff error of that operation. */
158 /* */
159 /* The operations Fast_Two_Sum(), Fast_Two_Diff(), Two_Sum(), Two_Diff(), */
160 /* Split(), and Two_Product() are all implemented as described in the */
161 /* reference. Each of these macros requires certain variables to be */
162 /* defined in the calling routine. The variables `bvirt', `c', `abig', */
163 /* `_i', `_j', `_k', `_l', `_m', and `_n' are declared `INEXACT' because */
164 /* they store the result of an operation that may incur roundoff error. */
165 /* The input parameter `x' (or the highest numbered `x_' parameter) must */
166 /* also be declared `INEXACT'. */
167
168 #define Fast_Two_Sum_Tail(a, b, x, y) \
169 bvirt = x - a; \
170 y = b - bvirt
171
172 #define Fast_Two_Sum(a, b, x, y) \
173 x = (REAL) (a + b); \
174 Fast_Two_Sum_Tail(a, b, x, y)
175
176 #define Fast_Two_Diff_Tail(a, b, x, y) \
177 bvirt = a - x; \
178 y = bvirt - b
179
180 #define Fast_Two_Diff(a, b, x, y) \
181 x = (REAL) (a - b); \
182 Fast_Two_Diff_Tail(a, b, x, y)
183
184 #define Two_Sum_Tail(a, b, x, y) \
185 bvirt = (REAL) (x - a); \
186 avirt = x - bvirt; \
187 bround = b - bvirt; \
188 around = a - avirt; \
189 y = around + bround
190
191 #define Two_Sum(a, b, x, y) \
192 x = (REAL) (a + b); \
193 Two_Sum_Tail(a, b, x, y)
194
195 #define Two_Diff_Tail(a, b, x, y) \
196 bvirt = (REAL) (a - x); \
197 avirt = x + bvirt; \
198 bround = bvirt - b; \
199 around = a - avirt; \
200 y = around + bround
201
202 #define Two_Diff(a, b, x, y) \
203 x = (REAL) (a - b); \
204 Two_Diff_Tail(a, b, x, y)
205
206 #define Split(a, ahi, alo) \
207 c = (REAL) (splitter * a); \
208 abig = (REAL) (c - a); \
209 ahi = c - abig; \
210 alo = a - ahi
211
212 #define Two_Product_Tail(a, b, x, y) \
213 Split(a, ahi, alo); \
214 Split(b, bhi, blo); \
215 err1 = x - (ahi * bhi); \
216 err2 = err1 - (alo * bhi); \
217 err3 = err2 - (ahi * blo); \
218 y = (alo * blo) - err3
219
220 #define Two_Product(a, b, x, y) \
221 x = (REAL) (a * b); \
222 Two_Product_Tail(a, b, x, y)
223
224 /* Two_Product_Presplit() is Two_Product() where one of the inputs has */
225 /* already been split. Avoids redundant splitting. */
226
227 #define Two_Product_Presplit(a, b, bhi, blo, x, y) \
228 x = (REAL) (a * b); \
229 Split(a, ahi, alo); \
230 err1 = x - (ahi * bhi); \
231 err2 = err1 - (alo * bhi); \
232 err3 = err2 - (ahi * blo); \
233 y = (alo * blo) - err3
234
235 /* Two_Product_2Presplit() is Two_Product() where both of the inputs have */
236 /* already been split. Avoids redundant splitting. */
237
238 #define Two_Product_2Presplit(a, ahi, alo, b, bhi, blo, x, y) \
239 x = (REAL) (a * b); \
240 err1 = x - (ahi * bhi); \
241 err2 = err1 - (alo * bhi); \
242 err3 = err2 - (ahi * blo); \
243 y = (alo * blo) - err3
244
245 /* Square() can be done more quickly than Two_Product(). */
246
247 #define Square_Tail(a, x, y) \
248 Split(a, ahi, alo); \
249 err1 = x - (ahi * ahi); \
250 err3 = err1 - ((ahi + ahi) * alo); \
251 y = (alo * alo) - err3
252
253 #define Square(a, x, y) \
254 x = (REAL) (a * a); \
255 Square_Tail(a, x, y)
256
257 /* Macros for summing expansions of various fixed lengths. These are all */
258 /* unrolled versions of Expansion_Sum(). */
259
260 #define Two_One_Sum(a1, a0, b, x2, x1, x0) \
261 Two_Sum(a0, b , _i, x0); \
262 Two_Sum(a1, _i, x2, x1)
263
264 #define Two_One_Diff(a1, a0, b, x2, x1, x0) \
265 Two_Diff(a0, b , _i, x0); \
266 Two_Sum( a1, _i, x2, x1)
267
268 #define Two_Two_Sum(a1, a0, b1, b0, x3, x2, x1, x0) \
269 Two_One_Sum(a1, a0, b0, _j, _0, x0); \
270 Two_One_Sum(_j, _0, b1, x3, x2, x1)
271
272 #define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0) \
273 Two_One_Diff(a1, a0, b0, _j, _0, x0); \
274 Two_One_Diff(_j, _0, b1, x3, x2, x1)
275
276 #define Four_One_Sum(a3, a2, a1, a0, b, x4, x3, x2, x1, x0) \
277 Two_One_Sum(a1, a0, b , _j, x1, x0); \
278 Two_One_Sum(a3, a2, _j, x4, x3, x2)
279
280 #define Four_Two_Sum(a3, a2, a1, a0, b1, b0, x5, x4, x3, x2, x1, x0) \
281 Four_One_Sum(a3, a2, a1, a0, b0, _k, _2, _1, _0, x0); \
282 Four_One_Sum(_k, _2, _1, _0, b1, x5, x4, x3, x2, x1)
283
284 #define Four_Four_Sum(a3, a2, a1, a0, b4, b3, b1, b0, x7, x6, x5, x4, x3, x2, \
285 x1, x0) \
286 Four_Two_Sum(a3, a2, a1, a0, b1, b0, _l, _2, _1, _0, x1, x0); \
287 Four_Two_Sum(_l, _2, _1, _0, b4, b3, x7, x6, x5, x4, x3, x2)
288
289 #define Eight_One_Sum(a7, a6, a5, a4, a3, a2, a1, a0, b, x8, x7, x6, x5, x4, \
290 x3, x2, x1, x0) \
291 Four_One_Sum(a3, a2, a1, a0, b , _j, x3, x2, x1, x0); \
292 Four_One_Sum(a7, a6, a5, a4, _j, x8, x7, x6, x5, x4)
293
294 #define Eight_Two_Sum(a7, a6, a5, a4, a3, a2, a1, a0, b1, b0, x9, x8, x7, \
295 x6, x5, x4, x3, x2, x1, x0) \
296 Eight_One_Sum(a7, a6, a5, a4, a3, a2, a1, a0, b0, _k, _6, _5, _4, _3, _2, \
297 _1, _0, x0); \
298 Eight_One_Sum(_k, _6, _5, _4, _3, _2, _1, _0, b1, x9, x8, x7, x6, x5, x4, \
299 x3, x2, x1)
300
301 #define Eight_Four_Sum(a7, a6, a5, a4, a3, a2, a1, a0, b4, b3, b1, b0, x11, \
302 x10, x9, x8, x7, x6, x5, x4, x3, x2, x1, x0) \
303 Eight_Two_Sum(a7, a6, a5, a4, a3, a2, a1, a0, b1, b0, _l, _6, _5, _4, _3, \
304 _2, _1, _0, x1, x0); \
305 Eight_Two_Sum(_l, _6, _5, _4, _3, _2, _1, _0, b4, b3, x11, x10, x9, x8, \
306 x7, x6, x5, x4, x3, x2)
307
308 /* Macros for multiplying expansions of various fixed lengths. */
309
310 #define Two_One_Product(a1, a0, b, x3, x2, x1, x0) \
311 Split(b, bhi, blo); \
312 Two_Product_Presplit(a0, b, bhi, blo, _i, x0); \
313 Two_Product_Presplit(a1, b, bhi, blo, _j, _0); \
314 Two_Sum(_i, _0, _k, x1); \
315 Fast_Two_Sum(_j, _k, x3, x2)
316
317 #define Four_One_Product(a3, a2, a1, a0, b, x7, x6, x5, x4, x3, x2, x1, x0) \
318 Split(b, bhi, blo); \
319 Two_Product_Presplit(a0, b, bhi, blo, _i, x0); \
320 Two_Product_Presplit(a1, b, bhi, blo, _j, _0); \
321 Two_Sum(_i, _0, _k, x1); \
322 Fast_Two_Sum(_j, _k, _i, x2); \
323 Two_Product_Presplit(a2, b, bhi, blo, _j, _0); \
324 Two_Sum(_i, _0, _k, x3); \
325 Fast_Two_Sum(_j, _k, _i, x4); \
326 Two_Product_Presplit(a3, b, bhi, blo, _j, _0); \
327 Two_Sum(_i, _0, _k, x5); \
328 Fast_Two_Sum(_j, _k, x7, x6)
329
330 #define Two_Two_Product(a1, a0, b1, b0, x7, x6, x5, x4, x3, x2, x1, x0) \
331 Split(a0, a0hi, a0lo); \
332 Split(b0, bhi, blo); \
333 Two_Product_2Presplit(a0, a0hi, a0lo, b0, bhi, blo, _i, x0); \
334 Split(a1, a1hi, a1lo); \
335 Two_Product_2Presplit(a1, a1hi, a1lo, b0, bhi, blo, _j, _0); \
336 Two_Sum(_i, _0, _k, _1); \
337 Fast_Two_Sum(_j, _k, _l, _2); \
338 Split(b1, bhi, blo); \
339 Two_Product_2Presplit(a0, a0hi, a0lo, b1, bhi, blo, _i, _0); \
340 Two_Sum(_1, _0, _k, x1); \
341 Two_Sum(_2, _k, _j, _1); \
342 Two_Sum(_l, _j, _m, _2); \
343 Two_Product_2Presplit(a1, a1hi, a1lo, b1, bhi, blo, _j, _0); \
344 Two_Sum(_i, _0, _n, _0); \
345 Two_Sum(_1, _0, _i, x2); \
346 Two_Sum(_2, _i, _k, _1); \
347 Two_Sum(_m, _k, _l, _2); \
348 Two_Sum(_j, _n, _k, _0); \
349 Two_Sum(_1, _0, _j, x3); \
350 Two_Sum(_2, _j, _i, _1); \
351 Two_Sum(_l, _i, _m, _2); \
352 Two_Sum(_1, _k, _i, x4); \
353 Two_Sum(_2, _i, _k, x5); \
354 Two_Sum(_m, _k, x7, x6)
355
356 /* An expansion of length two can be squared more quickly than finding the */
357 /* product of two different expansions of length two, and the result is */
358 /* guaranteed to have no more than six (rather than eight) components. */
359
360 #define Two_Square(a1, a0, x5, x4, x3, x2, x1, x0) \
361 Square(a0, _j, x0); \
362 _0 = a0 + a0; \
363 Two_Product(a1, _0, _k, _1); \
364 Two_One_Sum(_k, _1, _j, _l, _2, x1); \
365 Square(a1, _j, _1); \
366 Two_Two_Sum(_j, _1, _l, _2, x5, x4, x3, x2)
367
368 /* splitter = 2^ceiling(p / 2) + 1. Used to split floats in half. */
369 static REAL splitter;
370 static REAL epsilon; /* = 2^(-p). Used to estimate roundoff errors. */
371 /* A set of coefficients used to calculate maximum roundoff errors. */
372 static REAL resulterrbound;
373 static REAL ccwerrboundA, ccwerrboundB, ccwerrboundC;
374 static REAL o3derrboundA, o3derrboundB, o3derrboundC;
375 static REAL iccerrboundA, iccerrboundB, iccerrboundC;
376 static REAL isperrboundA, isperrboundB, isperrboundC;
377
378 /*****************************************************************************/
379 /* */
380 /* doubleprint() Print the bit representation of a double. */
381 /* */
382 /* Useful for debugging exact arithmetic routines. */
383 /* */
384 /*****************************************************************************/
385
386 /*
387 void doubleprint(number)
388 double number;
389 {
390 unsigned long long no;
391 unsigned long long sign, expo;
392 int exponent;
393 int i, bottomi;
394
395 no = *(unsigned long long *) &number;
396 sign = no & 0x8000000000000000ll;
397 expo = (no >> 52) & 0x7ffll;
398 exponent = (int) expo;
399 exponent = exponent - 1023;
400 if (sign) {
401 printf("-");
402 } else {
403 printf(" ");
404 }
405 if (exponent == -1023) {
406 printf(
407 "0.0000000000000000000000000000000000000000000000000000_ ( )");
408 } else {
409 printf("1.");
410 bottomi = -1;
411 for (i = 0; i < 52; i++) {
412 if (no & 0x0008000000000000ll) {
413 printf("1");
414 bottomi = i;
415 } else {
416 printf("0");
417 }
418 no <<= 1;
419 }
420 printf("_%d (%d)", exponent, exponent - 1 - bottomi);
421 }
422 }
423 */
424
425 /*****************************************************************************/
426 /* */
427 /* floatprint() Print the bit representation of a float. */
428 /* */
429 /* Useful for debugging exact arithmetic routines. */
430 /* */
431 /*****************************************************************************/
432
433 /*
434 void floatprint(number)
435 float number;
436 {
437 unsigned no;
438 unsigned sign, expo;
439 int exponent;
440 int i, bottomi;
441
442 no = *(unsigned *) &number;
443 sign = no & 0x80000000;
444 expo = (no >> 23) & 0xff;
445 exponent = (int) expo;
446 exponent = exponent - 127;
447 if (sign) {
448 printf("-");
449 } else {
450 printf(" ");
451 }
452 if (exponent == -127) {
453 printf("0.00000000000000000000000_ ( )");
454 } else {
455 printf("1.");
456 bottomi = -1;
457 for (i = 0; i < 23; i++) {
458 if (no & 0x00400000) {
459 printf("1");
460 bottomi = i;
461 } else {
462 printf("0");
463 }
464 no <<= 1;
465 }
466 printf("_%3d (%3d)", exponent, exponent - 1 - bottomi);
467 }
468 }
469 */
470
471 /*****************************************************************************/
472 /* */
473 /* expansion_print() Print the bit representation of an expansion. */
474 /* */
475 /* Useful for debugging exact arithmetic routines. */
476 /* */
477 /*****************************************************************************/
478
479 /*
480 void expansion_print(elen, e)
481 int elen;
482 REAL *e;
483 {
484 int i;
485
486 for (i = elen - 1; i >= 0; i--) {
487 REALPRINT(e[i]);
488 if (i > 0) {
489 printf(" +\n");
490 } else {
491 printf("\n");
492 }
493 }
494 }
495 */
496
497 /*****************************************************************************/
498 /* */
499 /* doublerand() Generate a double with random 53-bit significand and a */
500 /* random exponent in [0, 511]. */
501 /* */
502 /*****************************************************************************/
503
504 /*
505 double doublerand()
506 {
507 double result;
508 double expo;
509 long a, b, c;
510 long i;
511
512 a = random();
513 b = random();
514 c = random();
515 result = (double) (a - 1073741824) * 8388608.0 + (double) (b >> 8);
516 for (i = 512, expo = 2; i <= 131072; i *= 2, expo = expo * expo) {
517 if (c & i) {
518 result *= expo;
519 }
520 }
521 return result;
522 }
523 */
524
525 /*****************************************************************************/
526 /* */
527 /* narrowdoublerand() Generate a double with random 53-bit significand */
528 /* and a random exponent in [0, 7]. */
529 /* */
530 /*****************************************************************************/
531
532 /*
533 double narrowdoublerand()
534 {
535 double result;
536 double expo;
537 long a, b, c;
538 long i;
539
540 a = random();
541 b = random();
542 c = random();
543 result = (double) (a - 1073741824) * 8388608.0 + (double) (b >> 8);
544 for (i = 512, expo = 2; i <= 2048; i *= 2, expo = expo * expo) {
545 if (c & i) {
546 result *= expo;
547 }
548 }
549 return result;
550 }
551 */
552
553 /*****************************************************************************/
554 /* */
555 /* uniformdoublerand() Generate a double with random 53-bit significand. */
556 /* */
557 /*****************************************************************************/
558
559 /*
560 double uniformdoublerand()
561 {
562 double result;
563 long a, b;
564
565 a = random();
566 b = random();
567 result = (double) (a - 1073741824) * 8388608.0 + (double) (b >> 8);
568 return result;
569 }
570 */
571
572 /*****************************************************************************/
573 /* */
574 /* floatrand() Generate a float with random 24-bit significand and a */
575 /* random exponent in [0, 63]. */
576 /* */
577 /*****************************************************************************/
578
579 /*
580 float floatrand()
581 {
582 float result;
583 float expo;
584 long a, c;
585 long i;
586
587 a = random();
588 c = random();
589 result = (float) ((a - 1073741824) >> 6);
590 for (i = 512, expo = 2; i <= 16384; i *= 2, expo = expo * expo) {
591 if (c & i) {
592 result *= expo;
593 }
594 }
595 return result;
596 }
597 */
598
599 /*****************************************************************************/
600 /* */
601 /* narrowfloatrand() Generate a float with random 24-bit significand and */
602 /* a random exponent in [0, 7]. */
603 /* */
604 /*****************************************************************************/
605
606 /*
607 float narrowfloatrand()
608 {
609 float result;
610 float expo;
611 long a, c;
612 long i;
613
614 a = random();
615 c = random();
616 result = (float) ((a - 1073741824) >> 6);
617 for (i = 512, expo = 2; i <= 2048; i *= 2, expo = expo * expo) {
618 if (c & i) {
619 result *= expo;
620 }
621 }
622 return result;
623 }
624 */
625
626 /*****************************************************************************/
627 /* */
628 /* uniformfloatrand() Generate a float with random 24-bit significand. */
629 /* */
630 /*****************************************************************************/
631
632 /*
633 float uniformfloatrand()
634 {
635 float result;
636 long a;
637
638 a = random();
639 result = (float) ((a - 1073741824) >> 6);
640 return result;
641 }
642 */
643
644 /*****************************************************************************/
645 /* */
646 /* exactinit() Initialize the variables used for exact arithmetic. */
647 /* */
648 /* `epsilon' is the largest power of two such that 1.0 + epsilon = 1.0 in */
649 /* floating-point arithmetic. `epsilon' bounds the relative roundoff */
650 /* error. It is used for floating-point error analysis. */
651 /* */
652 /* `splitter' is used to split floating-point numbers into two half- */
653 /* length significands for exact multiplication. */
654 /* */
655 /* I imagine that a highly optimizing compiler might be too smart for its */
656 /* own good, and somehow cause this routine to fail, if it pretends that */
657 /* floating-point arithmetic is too much like real arithmetic. */
658 /* */
659 /* Don't change this routine unless you fully understand it. */
660 /* */
661 /*****************************************************************************/
662
663 REAL exactinit()
664 {
665 REAL half;
666 REAL check, lastcheck;
667 int every_other;
668 #ifdef LINUX
669 int cword;
670 #endif /* LINUX */
671
672 #ifdef CPU86
673 #ifdef SINGLE
674 _control87(_PC_24, _MCW_PC); /* Set FPU control word for single precision. */
675 #else /* not SINGLE */
676 _control87(_PC_53, _MCW_PC); /* Set FPU control word for double precision. */
677 #endif /* not SINGLE */
678 #endif /* CPU86 */
679 #ifdef LINUX
680 #ifdef SINGLE
681 /* cword = 4223; */
682 cword = 4210; /* set FPU control word for single precision */
683 #else /* not SINGLE */
684 /* cword = 4735; */
685 cword = 4722; /* set FPU control word for double precision */
686 #endif /* not SINGLE */
687 _FPU_SETCW(cword);
688 #endif /* LINUX */
689
690 every_other = 1;
691 half = 0.5;
692 epsilon = 1.0;
693 splitter = 1.0;
694 check = 1.0;
695 /* Repeatedly divide `epsilon' by two until it is too small to add to */
696 /* one without causing roundoff. (Also check if the sum is equal to */
697 /* the previous sum, for machines that round up instead of using exact */
698 /* rounding. Not that this library will work on such machines anyway. */
699 do {
700 lastcheck = check;
701 epsilon *= half;
702 if (every_other) {
703 splitter *= 2.0;
704 }
705 every_other = !every_other;
706 check = 1.0 + epsilon;
707 } while ((check != 1.0) && (check != lastcheck));
708 splitter += 1.0;
709
710 /* Error bounds for orientation and incircle tests. */
711 resulterrbound = (3.0 + 8.0 * epsilon) * epsilon;
712 ccwerrboundA = (3.0 + 16.0 * epsilon) * epsilon;
713 ccwerrboundB = (2.0 + 12.0 * epsilon) * epsilon;
714 ccwerrboundC = (9.0 + 64.0 * epsilon) * epsilon * epsilon;
715 o3derrboundA = (7.0 + 56.0 * epsilon) * epsilon;
716 o3derrboundB = (3.0 + 28.0 * epsilon) * epsilon;
717 o3derrboundC = (26.0 + 288.0 * epsilon) * epsilon * epsilon;
718 iccerrboundA = (10.0 + 96.0 * epsilon) * epsilon;
719 iccerrboundB = (4.0 + 48.0 * epsilon) * epsilon;
720 iccerrboundC = (44.0 + 576.0 * epsilon) * epsilon * epsilon;
721 isperrboundA = (16.0 + 224.0 * epsilon) * epsilon;
722 isperrboundB = (5.0 + 72.0 * epsilon) * epsilon;
723 isperrboundC = (71.0 + 1408.0 * epsilon) * epsilon * epsilon;
724
725 return epsilon; /* Added by H. Si 30 Juli, 2004. */
726 }
727
728 /*****************************************************************************/
729 /* */
730 /* grow_expansion() Add a scalar to an expansion. */
731 /* */
732 /* Sets h = e + b. See the long version of my paper for details. */
733 /* */
734 /* Maintains the nonoverlapping property. If round-to-even is used (as */
735 /* with IEEE 754), maintains the strongly nonoverlapping and nonadjacent */
736 /* properties as well. (That is, if e has one of these properties, so */
737 /* will h.) */
738 /* */
739 /*****************************************************************************/
740
741 int grow_expansion(int elen, REAL *e, REAL b, REAL *h)
742 /* e and h can be the same. */
743 {
744 REAL Q;
745 INEXACT REAL Qnew;
746 int eindex;
747 REAL enow;
748 INEXACT REAL bvirt;
749 REAL avirt, bround, around;
750
751 Q = b;
752 for (eindex = 0; eindex < elen; eindex++) {
753 enow = e[eindex];
754 Two_Sum(Q, enow, Qnew, h[eindex]);
755 Q = Qnew;
756 }
757 h[eindex] = Q;
758 return eindex + 1;
759 }
760
761 /*****************************************************************************/
762 /* */
763 /* grow_expansion_zeroelim() Add a scalar to an expansion, eliminating */
764 /* zero components from the output expansion. */
765 /* */
766 /* Sets h = e + b. See the long version of my paper for details. */
767 /* */
768 /* Maintains the nonoverlapping property. If round-to-even is used (as */
769 /* with IEEE 754), maintains the strongly nonoverlapping and nonadjacent */
770 /* properties as well. (That is, if e has one of these properties, so */
771 /* will h.) */
772 /* */
773 /*****************************************************************************/
774
775 int grow_expansion_zeroelim(int elen, REAL *e, REAL b, REAL *h)
776 /* e and h can be the same. */
777 {
778 REAL Q, hh;
779 INEXACT REAL Qnew;
780 int eindex, hindex;
781 REAL enow;
782 INEXACT REAL bvirt;
783 REAL avirt, bround, around;
784
785 hindex = 0;
786 Q = b;
787 for (eindex = 0; eindex < elen; eindex++) {
788 enow = e[eindex];
789 Two_Sum(Q, enow, Qnew, hh);
790 Q = Qnew;
791 if (hh != 0.0) {
792 h[hindex++] = hh;
793 }
794 }
795 if ((Q != 0.0) || (hindex == 0)) {
796 h[hindex++] = Q;
797 }
798 return hindex;
799 }
800
801 /*****************************************************************************/
802 /* */
803 /* expansion_sum() Sum two expansions. */
804 /* */
805 /* Sets h = e + f. See the long version of my paper for details. */
806 /* */
807 /* Maintains the nonoverlapping property. If round-to-even is used (as */
808 /* with IEEE 754), maintains the nonadjacent property as well. (That is, */
809 /* if e has one of these properties, so will h.) Does NOT maintain the */
810 /* strongly nonoverlapping property. */
811 /* */
812 /*****************************************************************************/
813
814 int expansion_sum(int elen, REAL *e, int flen, REAL *f, REAL *h)
815 /* e and h can be the same, but f and h cannot. */
816 {
817 REAL Q;
818 INEXACT REAL Qnew;
819 int findex, hindex, hlast;
820 REAL hnow;
821 INEXACT REAL bvirt;
822 REAL avirt, bround, around;
823
824 Q = f[0];
825 for (hindex = 0; hindex < elen; hindex++) {
826 hnow = e[hindex];
827 Two_Sum(Q, hnow, Qnew, h[hindex]);
828 Q = Qnew;
829 }
830 h[hindex] = Q;
831 hlast = hindex;
832 for (findex = 1; findex < flen; findex++) {
833 Q = f[findex];
834 for (hindex = findex; hindex <= hlast; hindex++) {
835 hnow = h[hindex];
836 Two_Sum(Q, hnow, Qnew, h[hindex]);
837 Q = Qnew;
838 }
839 h[++hlast] = Q;
840 }
841 return hlast + 1;
842 }
843
844 /*****************************************************************************/
845 /* */
846 /* expansion_sum_zeroelim1() Sum two expansions, eliminating zero */
847 /* components from the output expansion. */
848 /* */
849 /* Sets h = e + f. See the long version of my paper for details. */
850 /* */
851 /* Maintains the nonoverlapping property. If round-to-even is used (as */
852 /* with IEEE 754), maintains the nonadjacent property as well. (That is, */
853 /* if e has one of these properties, so will h.) Does NOT maintain the */
854 /* strongly nonoverlapping property. */
855 /* */
856 /*****************************************************************************/
857
858 int expansion_sum_zeroelim1(int elen, REAL *e, int flen, REAL *f, REAL *h)
859 /* e and h can be the same, but f and h cannot. */
860 {
861 REAL Q;
862 INEXACT REAL Qnew;
863 int index, findex, hindex, hlast;
864 REAL hnow;
865 INEXACT REAL bvirt;
866 REAL avirt, bround, around;
867
868 Q = f[0];
869 for (hindex = 0; hindex < elen; hindex++) {
870 hnow = e[hindex];
871 Two_Sum(Q, hnow, Qnew, h[hindex]);
872 Q = Qnew;
873 }
874 h[hindex] = Q;
875 hlast = hindex;
876 for (findex = 1; findex < flen; findex++) {
877 Q = f[findex];
878 for (hindex = findex; hindex <= hlast; hindex++) {
879 hnow = h[hindex];
880 Two_Sum(Q, hnow, Qnew, h[hindex]);
881 Q = Qnew;
882 }
883 h[++hlast] = Q;
884 }
885 hindex = -1;
886 for (index = 0; index <= hlast; index++) {
887 hnow = h[index];
888 if (hnow != 0.0) {
889 h[++hindex] = hnow;
890 }
891 }
892 if (hindex == -1) {
893 return 1;
894 } else {
895 return hindex + 1;
896 }
897 }
898
899 /*****************************************************************************/
900 /* */
901 /* expansion_sum_zeroelim2() Sum two expansions, eliminating zero */
902 /* components from the output expansion. */
903 /* */
904 /* Sets h = e + f. See the long version of my paper for details. */
905 /* */
906 /* Maintains the nonoverlapping property. If round-to-even is used (as */
907 /* with IEEE 754), maintains the nonadjacent property as well. (That is, */
908 /* if e has one of these properties, so will h.) Does NOT maintain the */
909 /* strongly nonoverlapping property. */
910 /* */
911 /*****************************************************************************/
912
913 int expansion_sum_zeroelim2(int elen, REAL *e, int flen, REAL *f, REAL *h)
914 /* e and h can be the same, but f and h cannot. */
915 {
916 REAL Q, hh;
917 INEXACT REAL Qnew;
918 int eindex, findex, hindex, hlast;
919 REAL enow;
920 INEXACT REAL bvirt;
921 REAL avirt, bround, around;
922
923 hindex = 0;
924 Q = f[0];
925 for (eindex = 0; eindex < elen; eindex++) {
926 enow = e[eindex];
927 Two_Sum(Q, enow, Qnew, hh);
928 Q = Qnew;
929 if (hh != 0.0) {
930 h[hindex++] = hh;
931 }
932 }
933 h[hindex] = Q;
934 hlast = hindex;
935 for (findex = 1; findex < flen; findex++) {
936 hindex = 0;
937 Q = f[findex];
938 for (eindex = 0; eindex <= hlast; eindex++) {
939 enow = h[eindex];
940 Two_Sum(Q, enow, Qnew, hh);
941 Q = Qnew;
942 if (hh != 0) {
943 h[hindex++] = hh;
944 }
945 }
946 h[hindex] = Q;
947 hlast = hindex;
948 }
949 return hlast + 1;
950 }
951
952 /*****************************************************************************/
953 /* */
954 /* fast_expansion_sum() Sum two expansions. */
955 /* */
956 /* Sets h = e + f. See the long version of my paper for details. */
957 /* */
958 /* If round-to-even is used (as with IEEE 754), maintains the strongly */
959 /* nonoverlapping property. (That is, if e is strongly nonoverlapping, h */
960 /* will be also.) Does NOT maintain the nonoverlapping or nonadjacent */
961 /* properties. */
962 /* */
963 /*****************************************************************************/
964
965 int fast_expansion_sum(int elen, REAL *e, int flen, REAL *f, REAL *h)
966 /* h cannot be e or f. */
967 {
968 REAL Q;
969 INEXACT REAL Qnew;
970 INEXACT REAL bvirt;
971 REAL avirt, bround, around;
972 int eindex, findex, hindex;
973 REAL enow, fnow;
974
975 enow = e[0];
976 fnow = f[0];
977 eindex = findex = 0;
978 if ((fnow > enow) == (fnow > -enow)) {
979 Q = enow;
980 enow = e[++eindex];
981 } else {
982 Q = fnow;
983 fnow = f[++findex];
984 }
985 hindex = 0;
986 if ((eindex < elen) && (findex < flen)) {
987 if ((fnow > enow) == (fnow > -enow)) {
988 Fast_Two_Sum(enow, Q, Qnew, h[0]);
989 enow = e[++eindex];
990 } else {
991 Fast_Two_Sum(fnow, Q, Qnew, h[0]);
992 fnow = f[++findex];
993 }
994 Q = Qnew;
995 hindex = 1;
996 while ((eindex < elen) && (findex < flen)) {
997 if ((fnow > enow) == (fnow > -enow)) {
998 Two_Sum(Q, enow, Qnew, h[hindex]);
999 enow = e[++eindex];
1000 } else {
1001 Two_Sum(Q, fnow, Qnew, h[hindex]);
1002 fnow = f[++findex];
1003 }
1004 Q = Qnew;
1005 hindex++;
1006 }
1007 }
1008 while (eindex < elen) {
1009 Two_Sum(Q, enow, Qnew, h[hindex]);
1010 enow = e[++eindex];
1011 Q = Qnew;
1012 hindex++;
1013 }
1014 while (findex < flen) {
1015 Two_Sum(Q, fnow, Qnew, h[hindex]);
1016 fnow = f[++findex];
1017 Q = Qnew;
1018 hindex++;
1019 }
1020 h[hindex] = Q;
1021 return hindex + 1;
1022 }
1023
1024 /*****************************************************************************/
1025 /* */
1026 /* fast_expansion_sum_zeroelim() Sum two expansions, eliminating zero */
1027 /* components from the output expansion. */
1028 /* */
1029 /* Sets h = e + f. See the long version of my paper for details. */
1030 /* */
1031 /* If round-to-even is used (as with IEEE 754), maintains the strongly */
1032 /* nonoverlapping property. (That is, if e is strongly nonoverlapping, h */
1033 /* will be also.) Does NOT maintain the nonoverlapping or nonadjacent */
1034 /* properties. */
1035 /* */
1036 /*****************************************************************************/
1037
1038 int fast_expansion_sum_zeroelim(int elen, REAL *e, int flen, REAL *f, REAL *h)
1039 /* h cannot be e or f. */
1040 {
1041 REAL Q;
1042 INEXACT REAL Qnew;
1043 INEXACT REAL hh;
1044 INEXACT REAL bvirt;
1045 REAL avirt, bround, around;
1046 int eindex, findex, hindex;
1047 REAL enow, fnow;
1048
1049 enow = e[0];
1050 fnow = f[0];
1051 eindex = findex = 0;
1052 if ((fnow > enow) == (fnow > -enow)) {
1053 Q = enow;
1054 enow = e[++eindex];
1055 } else {
1056 Q = fnow;
1057 fnow = f[++findex];
1058 }
1059 hindex = 0;
1060 if ((eindex < elen) && (findex < flen)) {
1061 if ((fnow > enow) == (fnow > -enow)) {
1062 Fast_Two_Sum(enow, Q, Qnew, hh);
1063 enow = e[++eindex];
1064 } else {
1065 Fast_Two_Sum(fnow, Q, Qnew, hh);
1066 fnow = f[++findex];
1067 }
1068 Q = Qnew;
1069 if (hh != 0.0) {
1070 h[hindex++] = hh;
1071 }
1072 while ((eindex < elen) && (findex < flen)) {
1073 if ((fnow > enow) == (fnow > -enow)) {
1074 Two_Sum(Q, enow, Qnew, hh);
1075 enow = e[++eindex];
1076 } else {
1077 Two_Sum(Q, fnow, Qnew, hh);
1078 fnow = f[++findex];
1079 }
1080 Q = Qnew;
1081 if (hh != 0.0) {
1082 h[hindex++] = hh;
1083 }
1084 }
1085 }
1086 while (eindex < elen) {
1087 Two_Sum(Q, enow, Qnew, hh);
1088 enow = e[++eindex];
1089 Q = Qnew;
1090 if (hh != 0.0) {
1091 h[hindex++] = hh;
1092 }
1093 }
1094 while (findex < flen) {
1095 Two_Sum(Q, fnow, Qnew, hh);
1096 fnow = f[++findex];
1097 Q = Qnew;
1098 if (hh != 0.0) {
1099 h[hindex++] = hh;
1100 }
1101 }
1102 if ((Q != 0.0) || (hindex == 0)) {
1103 h[hindex++] = Q;
1104 }
1105 return hindex;
1106 }
1107
1108 /*****************************************************************************/
1109 /* */
1110 /* linear_expansion_sum() Sum two expansions. */
1111 /* */
1112 /* Sets h = e + f. See either version of my paper for details. */
1113 /* */
1114 /* Maintains the nonoverlapping property. (That is, if e is */
1115 /* nonoverlapping, h will be also.) */
1116 /* */
1117 /*****************************************************************************/
1118
1119 int linear_expansion_sum(int elen, REAL *e, int flen, REAL *f, REAL *h)
1120 /* h cannot be e or f. */
1121 {
1122 REAL Q, q;
1123 INEXACT REAL Qnew;
1124 INEXACT REAL R;
1125 INEXACT REAL bvirt;
1126 REAL avirt, bround, around;
1127 int eindex, findex, hindex;
1128 REAL enow, fnow;
1129 REAL g0;
1130
1131 enow = e[0];
1132 fnow = f[0];
1133 eindex = findex = 0;
1134 if ((fnow > enow) == (fnow > -enow)) {
1135 g0 = enow;
1136 enow = e[++eindex];
1137 } else {
1138 g0 = fnow;
1139 fnow = f[++findex];
1140 }
1141 if ((eindex < elen) && ((findex >= flen)
1142 || ((fnow > enow) == (fnow > -enow)))) {
1143 Fast_Two_Sum(enow, g0, Qnew, q);
1144 enow = e[++eindex];
1145 } else {
1146 Fast_Two_Sum(fnow, g0, Qnew, q);
1147 fnow = f[++findex];
1148 }
1149 Q = Qnew;
1150 for (hindex = 0; hindex < elen + flen - 2; hindex++) {
1151 if ((eindex < elen) && ((findex >= flen)
1152 || ((fnow > enow) == (fnow > -enow)))) {
1153 Fast_Two_Sum(enow, q, R, h[hindex]);
1154 enow = e[++eindex];
1155 } else {
1156 Fast_Two_Sum(fnow, q, R, h[hindex]);
1157 fnow = f[++findex];
1158 }
1159 Two_Sum(Q, R, Qnew, q);
1160 Q = Qnew;
1161 }
1162 h[hindex] = q;
1163 h[hindex + 1] = Q;
1164 return hindex + 2;
1165 }
1166
1167 /*****************************************************************************/
1168 /* */
1169 /* linear_expansion_sum_zeroelim() Sum two expansions, eliminating zero */
1170 /* components from the output expansion. */
1171 /* */
1172 /* Sets h = e + f. See either version of my paper for details. */
1173 /* */
1174 /* Maintains the nonoverlapping property. (That is, if e is */
1175 /* nonoverlapping, h will be also.) */
1176 /* */
1177 /*****************************************************************************/
1178
1179 int linear_expansion_sum_zeroelim(int elen, REAL *e, int flen, REAL *f,
1180 REAL *h)
1181 /* h cannot be e or f. */
1182 {
1183 REAL Q, q, hh;
1184 INEXACT REAL Qnew;
1185 INEXACT REAL R;
1186 INEXACT REAL bvirt;
1187 REAL avirt, bround, around;
1188 int eindex, findex, hindex;
1189 int count;
1190 REAL enow, fnow;
1191 REAL g0;
1192
1193 enow = e[0];
1194 fnow = f[0];
1195 eindex = findex = 0;
1196 hindex = 0;
1197 if ((fnow > enow) == (fnow > -enow)) {
1198 g0 = enow;
1199 enow = e[++eindex];
1200 } else {
1201 g0 = fnow;
1202 fnow = f[++findex];
1203 }
1204 if ((eindex < elen) && ((findex >= flen)
1205 || ((fnow > enow) == (fnow > -enow)))) {
1206 Fast_Two_Sum(enow, g0, Qnew, q);
1207 enow = e[++eindex];
1208 } else {
1209 Fast_Two_Sum(fnow, g0, Qnew, q);
1210 fnow = f[++findex];
1211 }
1212 Q = Qnew;
1213 for (count = 2; count < elen + flen; count++) {
1214 if ((eindex < elen) && ((findex >= flen)
1215 || ((fnow > enow) == (fnow > -enow)))) {
1216 Fast_Two_Sum(enow, q, R, hh);
1217 enow = e[++eindex];
1218 } else {
1219 Fast_Two_Sum(fnow, q, R, hh);
1220 fnow = f[++findex];
1221 }
1222 Two_Sum(Q, R, Qnew, q);
1223 Q = Qnew;
1224 if (hh != 0) {
1225 h[hindex++] = hh;
1226 }
1227 }
1228 if (q != 0) {
1229 h[hindex++] = q;
1230 }
1231 if ((Q != 0.0) || (hindex == 0)) {
1232 h[hindex++] = Q;
1233 }
1234 return hindex;
1235 }
1236
1237 /*****************************************************************************/
1238 /* */
1239 /* scale_expansion() Multiply an expansion by a scalar. */
1240 /* */
1241 /* Sets h = be. See either version of my paper for details. */
1242 /* */
1243 /* Maintains the nonoverlapping property. If round-to-even is used (as */
1244 /* with IEEE 754), maintains the strongly nonoverlapping and nonadjacent */
1245 /* properties as well. (That is, if e has one of these properties, so */
1246 /* will h.) */
1247 /* */
1248 /*****************************************************************************/
1249
1250 int scale_expansion(int elen, REAL *e, REAL b, REAL *h)
1251 /* e and h cannot be the same. */
1252 {
1253 INEXACT REAL Q;
1254 INEXACT REAL sum;
1255 INEXACT REAL product1;
1256 REAL product0;
1257 int eindex, hindex;
1258 REAL enow;
1259 INEXACT REAL bvirt;
1260 REAL avirt, bround, around;
1261 INEXACT REAL c;
1262 INEXACT REAL abig;
1263 REAL ahi, alo, bhi, blo;
1264 REAL err1, err2, err3;
1265
1266 Split(b, bhi, blo);
1267 Two_Product_Presplit(e[0], b, bhi, blo, Q, h[0]);
1268 hindex = 1;
1269 for (eindex = 1; eindex < elen; eindex++) {
1270 enow = e[eindex];
1271 Two_Product_Presplit(enow, b, bhi, blo, product1, product0);
1272 Two_Sum(Q, product0, sum, h[hindex]);
1273 hindex++;
1274 Two_Sum(product1, sum, Q, h[hindex]);
1275 hindex++;
1276 }
1277 h[hindex] = Q;
1278 return elen + elen;
1279 }
1280
1281 /*****************************************************************************/
1282 /* */
1283 /* scale_expansion_zeroelim() Multiply an expansion by a scalar, */
1284 /* eliminating zero components from the */
1285 /* output expansion. */
1286 /* */
1287 /* Sets h = be. See either version of my paper for details. */
1288 /* */
1289 /* Maintains the nonoverlapping property. If round-to-even is used (as */
1290 /* with IEEE 754), maintains the strongly nonoverlapping and nonadjacent */
1291 /* properties as well. (That is, if e has one of these properties, so */
1292 /* will h.) */
1293 /* */
1294 /*****************************************************************************/
1295
1296 int scale_expansion_zeroelim(int elen, REAL *e, REAL b, REAL *h)
1297 /* e and h cannot be the same. */
1298 {
1299 INEXACT REAL Q, sum;
1300 REAL hh;
1301 INEXACT REAL product1;
1302 REAL product0;
1303 int eindex, hindex;
1304 REAL enow;
1305 INEXACT REAL bvirt;
1306 REAL avirt, bround, around;
1307 INEXACT REAL c;
1308 INEXACT REAL abig;
1309 REAL ahi, alo, bhi, blo;
1310 REAL err1, err2, err3;
1311
1312 Split(b, bhi, blo);
1313 Two_Product_Presplit(e[0], b, bhi, blo, Q, hh);
1314 hindex = 0;
1315 if (hh != 0) {
1316 h[hindex++] = hh;
1317 }
1318 for (eindex = 1; eindex < elen; eindex++) {
1319 enow = e[eindex];
1320 Two_Product_Presplit(enow, b, bhi, blo, product1, product0);
1321 Two_Sum(Q, product0, sum, hh);
1322 if (hh != 0) {
1323 h[hindex++] = hh;
1324 }
1325 Fast_Two_Sum(product1, sum, Q, hh);
1326 if (hh != 0) {
1327 h[hindex++] = hh;
1328 }
1329 }
1330 if ((Q != 0.0) || (hindex == 0)) {
1331 h[hindex++] = Q;
1332 }
1333 return hindex;
1334 }
1335
1336 /*****************************************************************************/
1337 /* */
1338 /* compress() Compress an expansion. */
1339 /* */
1340 /* See the long version of my paper for details. */
1341 /* */
1342 /* Maintains the nonoverlapping property. If round-to-even is used (as */
1343 /* with IEEE 754), then any nonoverlapping expansion is converted to a */
1344 /* nonadjacent expansion. */
1345 /* */
1346 /*****************************************************************************/
1347
1348 int compress(int elen, REAL *e, REAL *h)
1349 /* e and h may be the same. */
1350 {
1351 REAL Q, q;
1352 INEXACT REAL Qnew;
1353 int eindex, hindex;
1354 INEXACT REAL bvirt;
1355 REAL enow, hnow;
1356 int top, bottom;
1357
1358 bottom = elen - 1;
1359 Q = e[bottom];
1360 for (eindex = elen - 2; eindex >= 0; eindex--) {
1361 enow = e[eindex];
1362 Fast_Two_Sum(Q, enow, Qnew, q);
1363 if (q != 0) {
1364 h[bottom--] = Qnew;
1365 Q = q;
1366 } else {
1367 Q = Qnew;
1368 }
1369 }
1370 top = 0;
1371 for (hindex = bottom + 1; hindex < elen; hindex++) {
1372 hnow = h[hindex];
1373 Fast_Two_Sum(hnow, Q, Qnew, q);
1374 if (q != 0) {
1375 h[top++] = q;
1376 }
1377 Q = Qnew;
1378 }
1379 h[top] = Q;
1380 return top + 1;
1381 }
1382
1383 /*****************************************************************************/
1384 /* */
1385 /* estimate() Produce a one-word estimate of an expansion's value. */
1386 /* */
1387 /* See either version of my paper for details. */
1388 /* */
1389 /*****************************************************************************/
1390
1391 REAL estimate(int elen, REAL *e)
1392 {
1393 REAL Q;
1394 int eindex;
1395
1396 Q = e[0];
1397 for (eindex = 1; eindex < elen; eindex++) {
1398 Q += e[eindex];
1399 }
1400 return Q;
1401 }
1402
1403 /*****************************************************************************/
1404 /* */
1405 /* orient2dfast() Approximate 2D orientation test. Nonrobust. */
1406 /* orient2dexact() Exact 2D orientation test. Robust. */
1407 /* orient2dslow() Another exact 2D orientation test. Robust. */
1408 /* orient2d() Adaptive exact 2D orientation test. Robust. */
1409 /* */
1410 /* Return a positive value if the points pa, pb, and pc occur */
1411 /* in counterclockwise order; a negative value if they occur */
1412 /* in clockwise order; and zero if they are collinear. The */
1413 /* result is also a rough approximation of twice the signed */
1414 /* area of the triangle defined by the three points. */
1415 /* */
1416 /* Only the first and last routine should be used; the middle two are for */
1417 /* timings. */
1418 /* */
1419 /* The last three use exact arithmetic to ensure a correct answer. The */
1420 /* result returned is the determinant of a matrix. In orient2d() only, */
1421 /* this determinant is computed adaptively, in the sense that exact */
1422 /* arithmetic is used only to the degree it is needed to ensure that the */
1423 /* returned value has the correct sign. Hence, orient2d() is usually quite */
1424 /* fast, but will run more slowly when the input points are collinear or */
1425 /* nearly so. */
1426 /* */
1427 /*****************************************************************************/
1428
1429 REAL orient2dfast(REAL *pa, REAL *pb, REAL *pc)
1430 {
1431 REAL acx, bcx, acy, bcy;
1432
1433 acx = pa[0] - pc[0];
1434 bcx = pb[0] - pc[0];
1435 acy = pa[1] - pc[1];
1436 bcy = pb[1] - pc[1];
1437 return acx * bcy - acy * bcx;
1438 }
1439
1440 REAL orient2dexact(REAL *pa, REAL *pb, REAL *pc)
1441 {
1442 INEXACT REAL axby1, axcy1, bxcy1, bxay1, cxay1, cxby1;
1443 REAL axby0, axcy0, bxcy0, bxay0, cxay0, cxby0;
1444 REAL aterms[4], bterms[4], cterms[4];
1445 INEXACT REAL aterms3, bterms3, cterms3;
1446 REAL v[8], w[12];
1447 int vlength, wlength;
1448
1449 INEXACT REAL bvirt;
1450 REAL avirt, bround, around;
1451 INEXACT REAL c;
1452 INEXACT REAL abig;
1453 REAL ahi, alo, bhi, blo;
1454 REAL err1, err2, err3;
1455 INEXACT REAL _i, _j;
1456 REAL _0;
1457
1458 Two_Product(pa[0], pb[1], axby1, axby0);
1459 Two_Product(pa[0], pc[1], axcy1, axcy0);
1460 Two_Two_Diff(axby1, axby0, axcy1, axcy0,
1461 aterms3, aterms[2], aterms[1], aterms[0]);
1462 aterms[3] = aterms3;
1463
1464 Two_Product(pb[0], pc[1], bxcy1, bxcy0);
1465 Two_Product(pb[0], pa[1], bxay1, bxay0);
1466 Two_Two_Diff(bxcy1, bxcy0, bxay1, bxay0,
1467 bterms3, bterms[2], bterms[1], bterms[0]);
1468 bterms[3] = bterms3;
1469
1470 Two_Product(pc[0], pa[1], cxay1, cxay0);
1471 Two_Product(pc[0], pb[1], cxby1, cxby0);
1472 Two_Two_Diff(cxay1, cxay0, cxby1, cxby0,
1473 cterms3, cterms[2], cterms[1], cterms[0]);
1474 cterms[3] = cterms3;
1475
1476 vlength = fast_expansion_sum_zeroelim(4, aterms, 4, bterms, v);
1477 wlength = fast_expansion_sum_zeroelim(vlength, v, 4, cterms, w);
1478
1479 return w[wlength - 1];
1480 }
1481
1482 REAL orient2dslow(REAL *pa, REAL *pb, REAL *pc)
1483 {
1484 INEXACT REAL acx, acy, bcx, bcy;
1485 REAL acxtail, acytail;
1486 REAL bcxtail, bcytail;
1487 REAL negate, negatetail;
1488 REAL axby[8], bxay[8];
1489 INEXACT REAL axby7, bxay7;
1490 REAL deter[16];
1491 int deterlen;
1492
1493 INEXACT REAL bvirt;
1494 REAL avirt, bround, around;
1495 INEXACT REAL c;
1496 INEXACT REAL abig;
1497 REAL a0hi, a0lo, a1hi, a1lo, bhi, blo;
1498 REAL err1, err2, err3;
1499 INEXACT REAL _i, _j, _k, _l, _m, _n;
1500 REAL _0, _1, _2;
1501
1502 Two_Diff(pa[0], pc[0], acx, acxtail);
1503 Two_Diff(pa[1], pc[1], acy, acytail);
1504 Two_Diff(pb[0], pc[0], bcx, bcxtail);
1505 Two_Diff(pb[1], pc[1], bcy, bcytail);
1506
1507 Two_Two_Product(acx, acxtail, bcy, bcytail,
1508 axby7, axby[6], axby[5], axby[4],
1509 axby[3], axby[2], axby[1], axby[0]);
1510 axby[7] = axby7;
1511 negate = -acy;
1512 negatetail = -acytail;
1513 Two_Two_Product(bcx, bcxtail, negate, negatetail,
1514 bxay7, bxay[6], bxay[5], bxay[4],
1515 bxay[3], bxay[2], bxay[1], bxay[0]);
1516 bxay[7] = bxay7;
1517
1518 deterlen = fast_expansion_sum_zeroelim(8, axby, 8, bxay, deter);
1519
1520 return deter[deterlen - 1];
1521 }
1522
1523 REAL orient2dadapt(REAL *pa, REAL *pb, REAL *pc, REAL detsum)
1524 {
1525 INEXACT REAL acx, acy, bcx, bcy;
1526 REAL acxtail, acytail, bcxtail, bcytail;
1527 INEXACT REAL detleft, detright;
1528 REAL detlefttail, detrighttail;
1529 REAL det, errbound;
1530 REAL B[4], C1[8], C2[12], D[16];
1531 INEXACT REAL B3;
1532 int C1length, C2length, Dlength;
1533 REAL u[4];
1534 INEXACT REAL u3;
1535 INEXACT REAL s1, t1;
1536 REAL s0, t0;
1537
1538 INEXACT REAL bvirt;
1539 REAL avirt, bround, around;
1540 INEXACT REAL c;
1541 INEXACT REAL abig;
1542 REAL ahi, alo, bhi, blo;
1543 REAL err1, err2, err3;
1544 INEXACT REAL _i, _j;
1545 REAL _0;
1546
1547 acx = (REAL) (pa[0] - pc[0]);
1548 bcx = (REAL) (pb[0] - pc[0]);
1549 acy = (REAL) (pa[1] - pc[1]);
1550 bcy = (REAL) (pb[1] - pc[1]);
1551
1552 Two_Product(acx, bcy, detleft, detlefttail);
1553 Two_Product(acy, bcx, detright, detrighttail);
1554
1555 Two_Two_Diff(detleft, detlefttail, detright, detrighttail,
1556 B3, B[2], B[1], B[0]);
1557 B[3] = B3;
1558
1559 det = estimate(4, B);
1560 errbound = ccwerrboundB * detsum;
1561 if ((det >= errbound) || (-det >= errbound)) {
1562 return det;
1563 }
1564
1565 Two_Diff_Tail(pa[0], pc[0], acx, acxtail);
1566 Two_Diff_Tail(pb[0], pc[0], bcx, bcxtail);
1567 Two_Diff_Tail(pa[1], pc[1], acy, acytail);
1568 Two_Diff_Tail(pb[1], pc[1], bcy, bcytail);
1569
1570 if ((acxtail == 0.0) && (acytail == 0.0)
1571 && (bcxtail == 0.0) && (bcytail == 0.0)) {
1572 return det;
1573 }
1574
1575 errbound = ccwerrboundC * detsum + resulterrbound * Absolute(det);
1576 det += (acx * bcytail + bcy * acxtail)
1577 - (acy * bcxtail + bcx * acytail);
1578 if ((det >= errbound) || (-det >= errbound)) {
1579 return det;
1580 }
1581
1582 Two_Product(acxtail, bcy, s1, s0);
1583 Two_Product(acytail, bcx, t1, t0);
1584 Two_Two_Diff(s1, s0, t1, t0, u3, u[2], u[1], u[0]);
1585 u[3] = u3;
1586 C1length = fast_expansion_sum_zeroelim(4, B, 4, u, C1);
1587
1588 Two_Product(acx, bcytail, s1, s0);
1589 Two_Product(acy, bcxtail, t1, t0);
1590 Two_Two_Diff(s1, s0, t1, t0, u3, u[2], u[1], u[0]);
1591 u[3] = u3;
1592 C2length = fast_expansion_sum_zeroelim(C1length, C1, 4, u, C2);
1593
1594 Two_Product(acxtail, bcytail, s1, s0);
1595 Two_Product(acytail, bcxtail, t1, t0);
1596 Two_Two_Diff(s1, s0, t1, t0, u3, u[2], u[1], u[0]);
1597 u[3] = u3;
1598 Dlength = fast_expansion_sum_zeroelim(C2length, C2, 4, u, D);
1599
1600 return(D[Dlength - 1]);
1601 }
1602
1603 REAL orient2d(REAL *pa, REAL *pb, REAL *pc)
1604 {
1605 REAL detleft, detright, det;
1606 REAL detsum, errbound;
1607
1608 detleft = (pa[0] - pc[0]) * (pb[1] - pc[1]);
1609 detright = (pa[1] - pc[1]) * (pb[0] - pc[0]);
1610 det = detleft - detright;
1611
1612 if (detleft > 0.0) {
1613 if (detright <= 0.0) {
1614 return det;
1615 } else {
1616 detsum = detleft + detright;
1617 }
1618 } else if (detleft < 0.0) {
1619 if (detright >= 0.0) {
1620 return det;
1621 } else {
1622 detsum = -detleft - detright;
1623 }
1624 } else {
1625 return det;
1626 }
1627
1628 errbound = ccwerrboundA * detsum;
1629 if ((det >= errbound) || (-det >= errbound)) {
1630 return det;
1631 }
1632
1633 return orient2dadapt(pa, pb, pc, detsum);
1634 }
1635
1636 /*****************************************************************************/
1637 /* */
1638 /* orient3dfast() Approximate 3D orientation test. Nonrobust. */
1639 /* orient3dexact() Exact 3D orientation test. Robust. */
1640 /* orient3dslow() Another exact 3D orientation test. Robust. */
1641 /* orient3d() Adaptive exact 3D orientation test. Robust. */
1642 /* */
1643 /* Return a positive value if the point pd lies below the */
1644 /* plane passing through pa, pb, and pc; "below" is defined so */
1645 /* that pa, pb, and pc appear in counterclockwise order when */
1646 /* viewed from above the plane. Returns a negative value if */
1647 /* pd lies above the plane. Returns zero if the points are */
1648 /* coplanar. The result is also a rough approximation of six */
1649 /* times the signed volume of the tetrahedron defined by the */
1650 /* four points. */
1651 /* */
1652 /* Only the first and last routine should be used; the middle two are for */
1653 /* timings. */
1654 /* */
1655 /* The last three use exact arithmetic to ensure a correct answer. The */
1656 /* result returned is the determinant of a matrix. In orient3d() only, */
1657 /* this determinant is computed adaptively, in the sense that exact */
1658 /* arithmetic is used only to the degree it is needed to ensure that the */
1659 /* returned value has the correct sign. Hence, orient3d() is usually quite */
1660 /* fast, but will run more slowly when the input points are coplanar or */
1661 /* nearly so. */
1662 /* */
1663 /*****************************************************************************/
1664
1665 REAL orient3dfast(REAL *pa, REAL *pb, REAL *pc, REAL *pd)
1666 {
1667 REAL adx, bdx, cdx;
1668 REAL ady, bdy, cdy;
1669 REAL adz, bdz, cdz;
1670
1671 adx = pa[0] - pd[0];
1672 bdx = pb[0] - pd[0];
1673 cdx = pc[0] - pd[0];
1674 ady = pa[1] - pd[1];
1675 bdy = pb[1] - pd[1];
1676 cdy = pc[1] - pd[1];
1677 adz = pa[2] - pd[2];
1678 bdz = pb[2] - pd[2];
1679 cdz = pc[2] - pd[2];
1680
1681 return adx * (bdy * cdz - bdz * cdy)
1682 + bdx * (cdy * adz - cdz * ady)
1683 + cdx * (ady * bdz - adz * bdy);
1684 }
1685
1686 REAL orient3dexact(REAL *pa, REAL *pb, REAL *pc, REAL *pd)
1687 {
1688 INEXACT REAL axby1, bxcy1, cxdy1, dxay1, axcy1, bxdy1;
1689 INEXACT REAL bxay1, cxby1, dxcy1, axdy1, cxay1, dxby1;
1690 REAL axby0, bxcy0, cxdy0, dxay0, axcy0, bxdy0;
1691 REAL bxay0, cxby0, dxcy0, axdy0, cxay0, dxby0;
1692 REAL ab[4], bc[4], cd[4], da[4], ac[4], bd[4];
1693 REAL temp8[8];
1694 int templen;
1695 REAL abc[12], bcd[12], cda[12], dab[12];
1696 int abclen, bcdlen, cdalen, dablen;
1697 REAL adet[24], bdet[24], cdet[24], ddet[24];
1698 int alen, blen, clen, dlen;
1699 REAL abdet[48], cddet[48];
1700 int ablen, cdlen;
1701 REAL deter[96];
1702 int deterlen;
1703 int i;
1704
1705 INEXACT REAL bvirt;
1706 REAL avirt, bround, around;
1707 INEXACT REAL c;
1708 INEXACT REAL abig;
1709 REAL ahi, alo, bhi, blo;
1710 REAL err1, err2, err3;
1711 INEXACT REAL _i, _j;
1712 REAL _0;
1713
1714 Two_Product(pa[0], pb[1], axby1, axby0);
1715 Two_Product(pb[0], pa[1], bxay1, bxay0);
1716 Two_Two_Diff(axby1, axby0, bxay1, bxay0, ab[3], ab[2], ab[1], ab[0]);
1717
1718 Two_Product(pb[0], pc[1], bxcy1, bxcy0);
1719 Two_Product(pc[0], pb[1], cxby1, cxby0);
1720 Two_Two_Diff(bxcy1, bxcy0, cxby1, cxby0, bc[3], bc[2], bc[1], bc[0]);
1721
1722 Two_Product(pc[0], pd[1], cxdy1, cxdy0);
1723 Two_Product(pd[0], pc[1], dxcy1, dxcy0);
1724 Two_Two_Diff(cxdy1, cxdy0, dxcy1, dxcy0, cd[3], cd[2], cd[1], cd[0]);
1725
1726 Two_Product(pd[0], pa[1], dxay1, dxay0);
1727 Two_Product(pa[0], pd[1], axdy1, axdy0);
1728 Two_Two_Diff(dxay1, dxay0, axdy1, axdy0, da[3], da[2], da[1], da[0]);
1729
1730 Two_Product(pa[0], pc[1], axcy1, axcy0);
1731 Two_Product(pc[0], pa[1], cxay1, cxay0);
1732 Two_Two_Diff(axcy1, axcy0, cxay1, cxay0, ac[3], ac[2], ac[1], ac[0]);
1733
1734 Two_Product(pb[0], pd[1], bxdy1, bxdy0);
1735 Two_Product(pd[0], pb[1], dxby1, dxby0);
1736 Two_Two_Diff(bxdy1, bxdy0, dxby1, dxby0, bd[3], bd[2], bd[1], bd[0]);
1737
1738 templen = fast_expansion_sum_zeroelim(4, cd, 4, da, temp8);
1739 cdalen = fast_expansion_sum_zeroelim(templen, temp8, 4, ac, cda);
1740 templen = fast_expansion_sum_zeroelim(4, da, 4, ab, temp8);
1741 dablen = fast_expansion_sum_zeroelim(templen, temp8, 4, bd, dab);
1742 for (i = 0; i < 4; i++) {
1743 bd[i] = -bd[i];
1744 ac[i] = -ac[i];
1745 }
1746 templen = fast_expansion_sum_zeroelim(4, ab, 4, bc, temp8);
1747 abclen = fast_expansion_sum_zeroelim(templen, temp8, 4, ac, abc);
1748 templen = fast_expansion_sum_zeroelim(4, bc, 4, cd, temp8);
1749 bcdlen = fast_expansion_sum_zeroelim(templen, temp8, 4, bd, bcd);
1750
1751 alen = scale_expansion_zeroelim(bcdlen, bcd, pa[2], adet);
1752 blen = scale_expansion_zeroelim(cdalen, cda, -pb[2], bdet);
1753 clen = scale_expansion_zeroelim(dablen, dab, pc[2], cdet);
1754 dlen = scale_expansion_zeroelim(abclen, abc, -pd[2], ddet);
1755
1756 ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
1757 cdlen = fast_expansion_sum_zeroelim(clen, cdet, dlen, ddet, cddet);
1758 deterlen = fast_expansion_sum_zeroelim(ablen, abdet, cdlen, cddet, deter);
1759
1760 return deter[deterlen - 1];
1761 }
1762
1763 REAL orient3dslow(REAL *pa, REAL *pb, REAL *pc, REAL *pd)
1764 {
1765 INEXACT REAL adx, ady, adz, bdx, bdy, bdz, cdx, cdy, cdz;
1766 REAL adxtail, adytail, adztail;
1767 REAL bdxtail, bdytail, bdztail;
1768 REAL cdxtail, cdytail, cdztail;
1769 REAL negate, negatetail;
1770 INEXACT REAL axby7, bxcy7, axcy7, bxay7, cxby7, cxay7;
1771 REAL axby[8], bxcy[8], axcy[8], bxay[8], cxby[8], cxay[8];
1772 REAL temp16[16], temp32[32], temp32t[32];
1773 int temp16len, temp32len, temp32tlen;
1774 REAL adet[64], bdet[64], cdet[64];
1775 int alen, blen, clen;
1776 REAL abdet[128];
1777 int ablen;
1778 REAL deter[192];
1779 int deterlen;
1780
1781 INEXACT REAL bvirt;
1782 REAL avirt, bround, around;
1783 INEXACT REAL c;
1784 INEXACT REAL abig;
1785 REAL a0hi, a0lo, a1hi, a1lo, bhi, blo;
1786 REAL err1, err2, err3;
1787 INEXACT REAL _i, _j, _k, _l, _m, _n;
1788 REAL _0, _1, _2;
1789
1790 Two_Diff(pa[0], pd[0], adx, adxtail);
1791 Two_Diff(pa[1], pd[1], ady, adytail);
1792 Two_Diff(pa[2], pd[2], adz, adztail);
1793 Two_Diff(pb[0], pd[0], bdx, bdxtail);
1794 Two_Diff(pb[1], pd[1], bdy, bdytail);
1795 Two_Diff(pb[2], pd[2], bdz, bdztail);
1796 Two_Diff(pc[0], pd[0], cdx, cdxtail);
1797 Two_Diff(pc[1], pd[1], cdy, cdytail);
1798 Two_Diff(pc[2], pd[2], cdz, cdztail);
1799
1800 Two_Two_Product(adx, adxtail, bdy, bdytail,
1801 axby7, axby[6], axby[5], axby[4],
1802 axby[3], axby[2], axby[1], axby[0]);
1803 axby[7] = axby7;
1804 negate = -ady;
1805 negatetail = -adytail;
1806 Two_Two_Product(bdx, bdxtail, negate, negatetail,
1807 bxay7, bxay[6], bxay[5], bxay[4],
1808 bxay[3], bxay[2], bxay[1], bxay[0]);
1809 bxay[7] = bxay7;
1810 Two_Two_Product(bdx, bdxtail, cdy, cdytail,
1811 bxcy7, bxcy[6], bxcy[5], bxcy[4],
1812 bxcy[3], bxcy[2], bxcy[1], bxcy[0]);
1813 bxcy[7] = bxcy7;
1814 negate = -bdy;
1815 negatetail = -bdytail;
1816 Two_Two_Product(cdx, cdxtail, negate, negatetail,
1817 cxby7, cxby[6], cxby[5], cxby[4],
1818 cxby[3], cxby[2], cxby[1], cxby[0]);
1819 cxby[7] = cxby7;
1820 Two_Two_Product(cdx, cdxtail, ady, adytail,
1821 cxay7, cxay[6], cxay[5], cxay[4],
1822 cxay[3], cxay[2], cxay[1], cxay[0]);
1823 cxay[7] = cxay7;
1824 negate = -cdy;
1825 negatetail = -cdytail;
1826 Two_Two_Product(adx, adxtail, negate, negatetail,
1827 axcy7, axcy[6], axcy[5], axcy[4],
1828 axcy[3], axcy[2], axcy[1], axcy[0]);
1829 axcy[7] = axcy7;
1830
1831 temp16len = fast_expansion_sum_zeroelim(8, bxcy, 8, cxby, temp16);
1832 temp32len = scale_expansion_zeroelim(temp16len, temp16, adz, temp32);
1833 temp32tlen = scale_expansion_zeroelim(temp16len, temp16, adztail, temp32t);
1834 alen = fast_expansion_sum_zeroelim(temp32len, temp32, temp32tlen, temp32t,
1835 adet);
1836
1837 temp16len = fast_expansion_sum_zeroelim(8, cxay, 8, axcy, temp16);
1838 temp32len = scale_expansion_zeroelim(temp16len, temp16, bdz, temp32);
1839 temp32tlen = scale_expansion_zeroelim(temp16len, temp16, bdztail, temp32t);
1840 blen = fast_expansion_sum_zeroelim(temp32len, temp32, temp32tlen, temp32t,
1841 bdet);
1842
1843 temp16len = fast_expansion_sum_zeroelim(8, axby, 8, bxay, temp16);
1844 temp32len = scale_expansion_zeroelim(temp16len, temp16, cdz, temp32);
1845 temp32tlen = scale_expansion_zeroelim(temp16len, temp16, cdztail, temp32t);
1846 clen = fast_expansion_sum_zeroelim(temp32len, temp32, temp32tlen, temp32t,
1847 cdet);
1848
1849 ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
1850 deterlen = fast_expansion_sum_zeroelim(ablen, abdet, clen, cdet, deter);
1851
1852 return deter[deterlen - 1];
1853 }
1854
1855 REAL orient3dadapt(REAL *pa, REAL *pb, REAL *pc, REAL *pd, REAL permanent)
1856 {
1857 INEXACT REAL adx, bdx, cdx, ady, bdy, cdy, adz, bdz, cdz;
1858 REAL det, errbound;
1859
1860 INEXACT REAL bdxcdy1, cdxbdy1, cdxady1, adxcdy1, adxbdy1, bdxady1;
1861 REAL bdxcdy0, cdxbdy0, cdxady0, adxcdy0, adxbdy0, bdxady0;
1862 REAL bc[4], ca[4], ab[4];
1863 INEXACT REAL bc3, ca3, ab3;
1864 REAL adet[8], bdet[8], cdet[8];
1865 int alen, blen, clen;
1866 REAL abdet[16];
1867 int ablen;
1868 REAL *finnow, *finother, *finswap;
1869 REAL fin1[192], fin2[192];
1870 int finlength;
1871
1872 REAL adxtail, bdxtail, cdxtail;
1873 REAL adytail, bdytail, cdytail;
1874 REAL adztail, bdztail, cdztail;
1875 INEXACT REAL at_blarge, at_clarge;
1876 INEXACT REAL bt_clarge, bt_alarge;
1877 INEXACT REAL ct_alarge, ct_blarge;
1878 REAL at_b[4], at_c[4], bt_c[4], bt_a[4], ct_a[4], ct_b[4];
1879 int at_blen, at_clen, bt_clen, bt_alen, ct_alen, ct_blen;
1880 INEXACT REAL bdxt_cdy1, cdxt_bdy1, cdxt_ady1;
1881 INEXACT REAL adxt_cdy1, adxt_bdy1, bdxt_ady1;
1882 REAL bdxt_cdy0, cdxt_bdy0, cdxt_ady0;
1883 REAL adxt_cdy0, adxt_bdy0, bdxt_ady0;
1884 INEXACT REAL bdyt_cdx1, cdyt_bdx1, cdyt_adx1;
1885 INEXACT REAL adyt_cdx1, adyt_bdx1, bdyt_adx1;
1886 REAL bdyt_cdx0, cdyt_bdx0, cdyt_adx0;
1887 REAL adyt_cdx0, adyt_bdx0, bdyt_adx0;
1888 REAL bct[8], cat[8], abt[8];
1889 int bctlen, catlen, abtlen;
1890 INEXACT REAL bdxt_cdyt1, cdxt_bdyt1, cdxt_adyt1;
1891 INEXACT REAL adxt_cdyt1, adxt_bdyt1, bdxt_adyt1;
1892 REAL bdxt_cdyt0, cdxt_bdyt0, cdxt_adyt0;
1893 REAL adxt_cdyt0, adxt_bdyt0, bdxt_adyt0;
1894 REAL u[4], v[12], w[16];
1895 INEXACT REAL u3;
1896 int vlength, wlength;
1897 REAL negate;
1898
1899 INEXACT REAL bvirt;
1900 REAL avirt, bround, around;
1901 INEXACT REAL c;
1902 INEXACT REAL abig;
1903 REAL ahi, alo, bhi, blo;
1904 REAL err1, err2, err3;
1905 INEXACT REAL _i, _j, _k;
1906 REAL _0;
1907
1908 adx = (REAL) (pa[0] - pd[0]);
1909 bdx = (REAL) (pb[0] - pd[0]);
1910 cdx = (REAL) (pc[0] - pd[0]);
1911 ady = (REAL) (pa[1] - pd[1]);
1912 bdy = (REAL) (pb[1] - pd[1]);
1913 cdy = (REAL) (pc[1] - pd[1]);
1914 adz = (REAL) (pa[2] - pd[2]);
1915 bdz = (REAL) (pb[2] - pd[2]);
1916 cdz = (REAL) (pc[2] - pd[2]);
1917
1918 Two_Product(bdx, cdy, bdxcdy1, bdxcdy0);
1919 Two_Product(cdx, bdy, cdxbdy1, cdxbdy0);
1920 Two_Two_Diff(bdxcdy1, bdxcdy0, cdxbdy1, cdxbdy0, bc3, bc[2], bc[1], bc[0]);
1921 bc[3] = bc3;
1922 alen = scale_expansion_zeroelim(4, bc, adz, adet);
1923
1924 Two_Product(cdx, ady, cdxady1, cdxady0);
1925 Two_Product(adx, cdy, adxcdy1, adxcdy0);
1926 Two_Two_Diff(cdxady1, cdxady0, adxcdy1, adxcdy0, ca3, ca[2], ca[1], ca[0]);
1927 ca[3] = ca3;
1928 blen = scale_expansion_zeroelim(4, ca, bdz, bdet);
1929
1930 Two_Product(adx, bdy, adxbdy1, adxbdy0);
1931 Two_Product(bdx, ady, bdxady1, bdxady0);
1932 Two_Two_Diff(adxbdy1, adxbdy0, bdxady1, bdxady0, ab3, ab[2], ab[1], ab[0]);
1933 ab[3] = ab3;
1934 clen = scale_expansion_zeroelim(4, ab, cdz, cdet);
1935
1936 ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
1937 finlength = fast_expansion_sum_zeroelim(ablen, abdet, clen, cdet, fin1);
1938
1939 det = estimate(finlength, fin1);
1940 errbound = o3derrboundB * permanent;
1941 if ((det >= errbound) || (-det >= errbound)) {
1942 return det;
1943 }
1944
1945 Two_Diff_Tail(pa[0], pd[0], adx, adxtail);
1946 Two_Diff_Tail(pb[0], pd[0], bdx, bdxtail);
1947 Two_Diff_Tail(pc[0], pd[0], cdx, cdxtail);
1948 Two_Diff_Tail(pa[1], pd[1], ady, adytail);
1949 Two_Diff_Tail(pb[1], pd[1], bdy, bdytail);
1950 Two_Diff_Tail(pc[1], pd[1], cdy, cdytail);
1951 Two_Diff_Tail(pa[2], pd[2], adz, adztail);
1952 Two_Diff_Tail(pb[2], pd[2], bdz, bdztail);
1953 Two_Diff_Tail(pc[2], pd[2], cdz, cdztail);
1954
1955 if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0)
1956 && (adytail == 0.0) && (bdytail == 0.0) && (cdytail == 0.0)
1957 && (adztail == 0.0) && (bdztail == 0.0) && (cdztail == 0.0)) {
1958 return det;
1959 }
1960
1961 errbound = o3derrboundC * permanent + resulterrbound * Absolute(det);
1962 det += (adz * ((bdx * cdytail + cdy * bdxtail)
1963 - (bdy * cdxtail + cdx * bdytail))
1964 + adztail * (bdx * cdy - bdy * cdx))
1965 + (bdz * ((cdx * adytail + ady * cdxtail)
1966 - (cdy * adxtail + adx * cdytail))
1967 + bdztail * (cdx * ady - cdy * adx))
1968 + (cdz * ((adx * bdytail + bdy * adxtail)
1969 - (ady * bdxtail + bdx * adytail))
1970 + cdztail * (adx * bdy - ady * bdx));
1971 if ((det >= errbound) || (-det >= errbound)) {
1972 return det;
1973 }
1974
1975 finnow = fin1;
1976 finother = fin2;
1977
1978 if (adxtail == 0.0) {
1979 if (adytail == 0.0) {
1980 at_b[0] = 0.0;
1981 at_blen = 1;
1982 at_c[0] = 0.0;
1983 at_clen = 1;
1984 } else {
1985 negate = -adytail;
1986 Two_Product(negate, bdx, at_blarge, at_b[0]);
1987 at_b[1] = at_blarge;
1988 at_blen = 2;
1989 Two_Product(adytail, cdx, at_clarge, at_c[0]);
1990 at_c[1] = at_clarge;
1991 at_clen = 2;
1992 }
1993 } else {
1994 if (adytail == 0.0) {
1995 Two_Product(adxtail, bdy, at_blarge, at_b[0]);
1996 at_b[1] = at_blarge;
1997 at_blen = 2;
1998 negate = -adxtail;
1999 Two_Product(negate, cdy, at_clarge, at_c[0]);
2000 at_c[1] = at_clarge;
2001 at_clen = 2;
2002 } else {
2003 Two_Product(adxtail, bdy, adxt_bdy1, adxt_bdy0);
2004 Two_Product(adytail, bdx, adyt_bdx1, adyt_bdx0);
2005 Two_Two_Diff(adxt_bdy1, adxt_bdy0, adyt_bdx1, adyt_bdx0,
2006 at_blarge, at_b[2], at_b[1], at_b[0]);
2007 at_b[3] = at_blarge;
2008 at_blen = 4;
2009 Two_Product(adytail, cdx, adyt_cdx1, adyt_cdx0);
2010 Two_Product(adxtail, cdy, adxt_cdy1, adxt_cdy0);
2011 Two_Two_Diff(adyt_cdx1, adyt_cdx0, adxt_cdy1, adxt_cdy0,
2012 at_clarge, at_c[2], at_c[1], at_c[0]);
2013 at_c[3] = at_clarge;
2014 at_clen = 4;
2015 }
2016 }
2017 if (bdxtail == 0.0) {
2018 if (bdytail == 0.0) {
2019 bt_c[0] = 0.0;
2020 bt_clen = 1;
2021 bt_a[0] = 0.0;
2022 bt_alen = 1;
2023 } else {
2024 negate = -bdytail;
2025 Two_Product(negate, cdx, bt_clarge, bt_c[0]);
2026 bt_c[1] = bt_clarge;
2027 bt_clen = 2;
2028 Two_Product(bdytail, adx, bt_alarge, bt_a[0]);
2029 bt_a[1] = bt_alarge;
2030 bt_alen = 2;
2031 }
2032 } else {
2033 if (bdytail == 0.0) {
2034 Two_Product(bdxtail, cdy, bt_clarge, bt_c[0]);
2035 bt_c[1] = bt_clarge;
2036 bt_clen = 2;
2037 negate = -bdxtail;
2038 Two_Product(negate, ady, bt_alarge, bt_a[0]);
2039 bt_a[1] = bt_alarge;
2040 bt_alen = 2;
2041 } else {
2042 Two_Product(bdxtail, cdy, bdxt_cdy1, bdxt_cdy0);
2043 Two_Product(bdytail, cdx, bdyt_cdx1, bdyt_cdx0);
2044 Two_Two_Diff(bdxt_cdy1, bdxt_cdy0, bdyt_cdx1, bdyt_cdx0,
2045 bt_clarge, bt_c[2], bt_c[1], bt_c[0]);
2046 bt_c[3] = bt_clarge;
2047 bt_clen = 4;
2048 Two_Product(bdytail, adx, bdyt_adx1, bdyt_adx0);
2049 Two_Product(bdxtail, ady, bdxt_ady1, bdxt_ady0);
2050 Two_Two_Diff(bdyt_adx1, bdyt_adx0, bdxt_ady1, bdxt_ady0,
2051 bt_alarge, bt_a[2], bt_a[1], bt_a[0]);
2052 bt_a[3] = bt_alarge;
2053 bt_alen = 4;
2054 }
2055 }
2056 if (cdxtail == 0.0) {
2057 if (cdytail == 0.0) {
2058 ct_a[0] = 0.0;
2059 ct_alen = 1;
2060 ct_b[0] = 0.0;
2061 ct_blen = 1;
2062 } else {
2063 negate = -cdytail;
2064 Two_Product(negate, adx, ct_alarge, ct_a[0]);
2065 ct_a[1] = ct_alarge;
2066 ct_alen = 2;
2067 Two_Product(cdytail, bdx, ct_blarge, ct_b[0]);
2068 ct_b[1] = ct_blarge;
2069 ct_blen = 2;
2070 }
2071 } else {
2072 if (cdytail == 0.0) {
2073 Two_Product(cdxtail, ady, ct_alarge, ct_a[0]);
2074 ct_a[1] = ct_alarge;
2075 ct_alen = 2;
2076 negate = -cdxtail;
2077 Two_Product(negate, bdy, ct_blarge, ct_b[0]);
2078 ct_b[1] = ct_blarge;
2079 ct_blen = 2;
2080 } else {
2081 Two_Product(cdxtail, ady, cdxt_ady1, cdxt_ady0);
2082 Two_Product(cdytail, adx, cdyt_adx1, cdyt_adx0);
2083 Two_Two_Diff(cdxt_ady1, cdxt_ady0, cdyt_adx1, cdyt_adx0,
2084 ct_alarge, ct_a[2], ct_a[1], ct_a[0]);
2085 ct_a[3] = ct_alarge;
2086 ct_alen = 4;
2087 Two_Product(cdytail, bdx, cdyt_bdx1, cdyt_bdx0);
2088 Two_Product(cdxtail, bdy, cdxt_bdy1, cdxt_bdy0);
2089 Two_Two_Diff(cdyt_bdx1, cdyt_bdx0, cdxt_bdy1, cdxt_bdy0,
2090 ct_blarge, ct_b[2], ct_b[1], ct_b[0]);
2091 ct_b[3] = ct_blarge;
2092 ct_blen = 4;
2093 }
2094 }
2095
2096 bctlen = fast_expansion_sum_zeroelim(bt_clen, bt_c, ct_blen, ct_b, bct);
2097 wlength = scale_expansion_zeroelim(bctlen, bct, adz, w);
2098 finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w,
2099 finother);
2100 finswap = finnow; finnow = finother; finother = finswap;
2101
2102 catlen = fast_expansion_sum_zeroelim(ct_alen, ct_a, at_clen, at_c, cat);
2103 wlength = scale_expansion_zeroelim(catlen, cat, bdz, w);
2104 finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w,
2105 finother);
2106 finswap = finnow; finnow = finother; finother = finswap;
2107
2108 abtlen = fast_expansion_sum_zeroelim(at_blen, at_b, bt_alen, bt_a, abt);
2109 wlength = scale_expansion_zeroelim(abtlen, abt, cdz, w);
2110 finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w,
2111 finother);
2112 finswap = finnow; finnow = finother; finother = finswap;
2113
2114 if (adztail != 0.0) {
2115 vlength = scale_expansion_zeroelim(4, bc, adztail, v);
2116 finlength = fast_expansion_sum_zeroelim(finlength, finnow, vlength, v,
2117 finother);
2118 finswap = finnow; finnow = finother; finother = finswap;
2119 }
2120 if (bdztail != 0.0) {
2121 vlength = scale_expansion_zeroelim(4, ca, bdztail, v);
2122 finlength = fast_expansion_sum_zeroelim(finlength, finnow, vlength, v,
2123 finother);
2124 finswap = finnow; finnow = finother; finother = finswap;
2125 }
2126 if (cdztail != 0.0) {
2127 vlength = scale_expansion_zeroelim(4, ab, cdztail, v);
2128 finlength = fast_expansion_sum_zeroelim(finlength, finnow, vlength, v,
2129 finother);
2130 finswap = finnow; finnow = finother; finother = finswap;
2131 }
2132
2133 if (adxtail != 0.0) {
2134 if (bdytail != 0.0) {
2135 Two_Product(adxtail, bdytail, adxt_bdyt1, adxt_bdyt0);
2136 Two_One_Product(adxt_bdyt1, adxt_bdyt0, cdz, u3, u[2], u[1], u[0]);
2137 u[3] = u3;
2138 finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u,
2139 finother);
2140 finswap = finnow; finnow = finother; finother = finswap;
2141 if (cdztail != 0.0) {
2142 Two_One_Product(adxt_bdyt1, adxt_bdyt0, cdztail, u3, u[2], u[1], u[0]);
2143 u[3] = u3;
2144 finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u,
2145 finother);
2146 finswap = finnow; finnow = finother; finother = finswap;
2147 }
2148 }
2149 if (cdytail != 0.0) {
2150 negate = -adxtail;
2151 Two_Product(negate, cdytail, adxt_cdyt1, adxt_cdyt0);
2152 Two_One_Product(adxt_cdyt1, adxt_cdyt0, bdz, u3, u[2], u[1], u[0]);
2153 u[3] = u3;
2154 finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u,
2155 finother);
2156 finswap = finnow; finnow = finother; finother = finswap;
2157 if (bdztail != 0.0) {
2158 Two_One_Product(adxt_cdyt1, adxt_cdyt0, bdztail, u3, u[2], u[1], u[0]);
2159 u[3] = u3;
2160 finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u,
2161 finother);
2162 finswap = finnow; finnow = finother; finother = finswap;
2163 }
2164 }
2165 }
2166 if (bdxtail != 0.0) {
2167 if (cdytail != 0.0) {
2168 Two_Product(bdxtail, cdytail, bdxt_cdyt1, bdxt_cdyt0);
2169 Two_One_Product(bdxt_cdyt1, bdxt_cdyt0, adz, u3, u[2], u[1], u[0]);
2170 u[3] = u3;
2171 finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u,
2172 finother);
2173 finswap = finnow; finnow = finother; finother = finswap;
2174 if (adztail != 0.0) {
2175 Two_One_Product(bdxt_cdyt1, bdxt_cdyt0, adztail, u3, u[2], u[1], u[0]);
2176 u[3] = u3;
2177 finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u,
2178 finother);
2179 finswap = finnow; finnow = finother; finother = finswap;
2180 }
2181 }
2182 if (adytail != 0.0) {
2183 negate = -bdxtail;
2184 Two_Product(negate, adytail, bdxt_adyt1, bdxt_adyt0);
2185 Two_One_Product(bdxt_adyt1, bdxt_adyt0, cdz, u3, u[2], u[1], u[0]);
2186 u[3] = u3;
2187 finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u,
2188 finother);
2189 finswap = finnow; finnow = finother; finother = finswap;
2190 if (cdztail != 0.0) {
2191 Two_One_Product(bdxt_adyt1, bdxt_adyt0, cdztail, u3, u[2], u[1], u[0]);
2192 u[3] = u3;
2193 finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u,
2194 finother);
2195 finswap = finnow; finnow = finother; finother = finswap;
2196 }
2197 }
2198 }
2199 if (cdxtail != 0.0) {
2200 if (adytail != 0.0) {
2201 Two_Product(cdxtail, adytail, cdxt_adyt1, cdxt_adyt0);
2202 Two_One_Product(cdxt_adyt1, cdxt_adyt0, bdz, u3, u[2], u[1], u[0]);
2203 u[3] = u3;
2204 finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u,
2205 finother);
2206 finswap = finnow; finnow = finother; finother = finswap;
2207 if (bdztail != 0.0) {
2208 Two_One_Product(cdxt_adyt1, cdxt_adyt0, bdztail, u3, u[2], u[1], u[0]);
2209 u[3] = u3;
2210 finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u,
2211 finother);
2212 finswap = finnow; finnow = finother; finother = finswap;
2213 }
2214 }
2215 if (bdytail != 0.0) {
2216 negate = -cdxtail;
2217 Two_Product(negate, bdytail, cdxt_bdyt1, cdxt_bdyt0);
2218 Two_One_Product(cdxt_bdyt1, cdxt_bdyt0, adz, u3, u[2], u[1], u[0]);
2219 u[3] = u3;
2220 finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u,
2221 finother);
2222 finswap = finnow; finnow = finother; finother = finswap;
2223 if (adztail != 0.0) {
2224 Two_One_Product(cdxt_bdyt1, cdxt_bdyt0, adztail, u3, u[2], u[1], u[0]);
2225 u[3] = u3;
2226 finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u,
2227 finother);
2228 finswap = finnow; finnow = finother; finother = finswap;
2229 }
2230 }
2231 }
2232
2233 if (adztail != 0.0) {
2234 wlength = scale_expansion_zeroelim(bctlen, bct, adztail, w);
2235 finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w,
2236 finother);
2237 finswap = finnow; finnow = finother; finother = finswap;
2238 }
2239 if (bdztail != 0.0) {
2240 wlength = scale_expansion_zeroelim(catlen, cat, bdztail, w);
2241 finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w,
2242 finother);
2243 finswap = finnow; finnow = finother; finother = finswap;
2244 }
2245 if (cdztail != 0.0) {
2246 wlength = scale_expansion_zeroelim(abtlen, abt, cdztail, w);
2247 finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w,
2248 finother);
2249 finswap = finnow; finnow = finother; finother = finswap;
2250 }
2251
2252 return finnow[finlength - 1];
2253 }
2254
2255 REAL orient3d(REAL *pa, REAL *pb, REAL *pc, REAL *pd)
2256 {
2257 REAL adx, bdx, cdx, ady, bdy, cdy, adz, bdz, cdz;
2258 REAL bdxcdy, cdxbdy, cdxady, adxcdy, adxbdy, bdxady;
2259 REAL det;
2260 REAL permanent, errbound;
2261
2262 adx = pa[0] - pd[0];
2263 bdx = pb[0] - pd[0];
2264 cdx = pc[0] - pd[0];
2265 ady = pa[1] - pd[1];
2266 bdy = pb[1] - pd[1];
2267 cdy = pc[1] - pd[1];
2268 adz = pa[2] - pd[2];
2269 bdz = pb[2] - pd[2];
2270 cdz = pc[2] - pd[2];
2271
2272 bdxcdy = bdx * cdy;
2273 cdxbdy = cdx * bdy;
2274
2275 cdxady = cdx * ady;
2276 adxcdy = adx * cdy;
2277
2278 adxbdy = adx * bdy;
2279 bdxady = bdx * ady;
2280
2281 det = adz * (bdxcdy - cdxbdy)
2282 + bdz * (cdxady - adxcdy)
2283 + cdz * (adxbdy - bdxady);
2284
2285 permanent = (Absolute(bdxcdy) + Absolute(cdxbdy)) * Absolute(adz)
2286 + (Absolute(cdxady) + Absolute(adxcdy)) * Absolute(bdz)
2287 + (Absolute(adxbdy) + Absolute(bdxady)) * Absolute(cdz);
2288 errbound = o3derrboundA * permanent;
2289 if ((det > errbound) || (-det > errbound)) {
2290 return det;
2291 }
2292
2293 return orient3dadapt(pa, pb, pc, pd, permanent);
2294 }
2295
2296 /*****************************************************************************/
2297 /* */
2298 /* incirclefast() Approximate 2D incircle test. Nonrobust. */
2299 /* incircleexact() Exact 2D incircle test. Robust. */
2300 /* incircleslow() Another exact 2D incircle test. Robust. */
2301 /* incircle() Adaptive exact 2D incircle test. Robust. */
2302 /* */
2303 /* Return a positive value if the point pd lies inside the */
2304 /* circle passing through pa, pb, and pc; a negative value if */
2305 /* it lies outside; and zero if the four points are cocircular.*/
2306 /* The points pa, pb, and pc must be in counterclockwise */
2307 /* order, or the sign of the result will be reversed. */
2308 /* */
2309 /* Only the first and last routine should be used; the middle two are for */
2310 /* timings. */
2311 /* */
2312 /* The last three use exact arithmetic to ensure a correct answer. The */
2313 /* result returned is the determinant of a matrix. In incircle() only, */
2314 /* this determinant is computed adaptively, in the sense that exact */
2315 /* arithmetic is used only to the degree it is needed to ensure that the */
2316 /* returned value has the correct sign. Hence, incircle() is usually quite */
2317 /* fast, but will run more slowly when the input points are cocircular or */
2318 /* nearly so. */
2319 /* */
2320 /*****************************************************************************/
2321
2322 REAL incirclefast(REAL *pa, REAL *pb, REAL *pc, REAL *pd)
2323 {
2324 REAL adx, ady, bdx, bdy, cdx, cdy;
2325 REAL abdet, bcdet, cadet;
2326 REAL alift, blift, clift;
2327
2328 adx = pa[0] - pd[0];
2329 ady = pa[1] - pd[1];
2330 bdx = pb[0] - pd[0];
2331 bdy = pb[1] - pd[1];
2332 cdx = pc[0] - pd[0];
2333 cdy = pc[1] - pd[1];
2334
2335 abdet = adx * bdy - bdx * ady;
2336 bcdet = bdx * cdy - cdx * bdy;
2337 cadet = cdx * ady - adx * cdy;
2338 alift = adx * adx + ady * ady;
2339 blift = bdx * bdx + bdy * bdy;
2340 clift = cdx * cdx + cdy * cdy;
2341
2342 return alift * bcdet + blift * cadet + clift * abdet;
2343 }
2344
2345 REAL incircleexact(REAL *pa, REAL *pb, REAL *pc, REAL *pd)
2346 {
2347 INEXACT REAL axby1, bxcy1, cxdy1, dxay1, axcy1, bxdy1;
2348 INEXACT REAL bxay1, cxby1, dxcy1, axdy1, cxay1, dxby1;
2349 REAL axby0, bxcy0, cxdy0, dxay0, axcy0, bxdy0;
2350 REAL bxay0, cxby0, dxcy0, axdy0, cxay0, dxby0;
2351 REAL ab[4], bc[4], cd[4], da[4], ac[4], bd[4];
2352 REAL temp8[8];
2353 int templen;
2354 REAL abc[12], bcd[12], cda[12], dab[12];
2355 int abclen, bcdlen, cdalen, dablen;
2356 REAL det24x[24], det24y[24], det48x[48], det48y[48];
2357 int xlen, ylen;
2358 REAL adet[96], bdet[96], cdet[96], ddet[96];
2359 int alen, blen, clen, dlen;
2360 REAL abdet[192], cddet[192];
2361 int ablen, cdlen;
2362 REAL deter[384];
2363 int deterlen;
2364 int i;
2365
2366 INEXACT REAL bvirt;
2367 REAL avirt, bround, around;
2368 INEXACT REAL c;
2369 INEXACT REAL abig;
2370 REAL ahi, alo, bhi, blo;
2371 REAL err1, err2, err3;
2372 INEXACT REAL _i, _j;
2373 REAL _0;
2374
2375 Two_Product(pa[0], pb[1], axby1, axby0);
2376 Two_Product(pb[0], pa[1], bxay1, bxay0);
2377 Two_Two_Diff(axby1, axby0, bxay1, bxay0, ab[3], ab[2], ab[1], ab[0]);
2378
2379 Two_Product(pb[0], pc[1], bxcy1, bxcy0);
2380 Two_Product(pc[0], pb[1], cxby1, cxby0);
2381 Two_Two_Diff(bxcy1, bxcy0, cxby1, cxby0, bc[3], bc[2], bc[1], bc[0]);
2382
2383 Two_Product(pc[0], pd[1], cxdy1, cxdy0);
2384 Two_Product(pd[0], pc[1], dxcy1, dxcy0);
2385 Two_Two_Diff(cxdy1, cxdy0, dxcy1, dxcy0, cd[3], cd[2], cd[1], cd[0]);
2386
2387 Two_Product(pd[0], pa[1], dxay1, dxay0);
2388 Two_Product(pa[0], pd[1], axdy1, axdy0);
2389 Two_Two_Diff(dxay1, dxay0, axdy1, axdy0, da[3], da[2], da[1], da[0]);
2390
2391 Two_Product(pa[0], pc[1], axcy1, axcy0);
2392 Two_Product(pc[0], pa[1], cxay1, cxay0);
2393 Two_Two_Diff(axcy1, axcy0, cxay1, cxay0, ac[3], ac[2], ac[1], ac[0]);
2394
2395 Two_Product(pb[0], pd[1], bxdy1, bxdy0);
2396 Two_Product(pd[0], pb[1], dxby1, dxby0);
2397 Two_Two_Diff(bxdy1, bxdy0, dxby1, dxby0, bd[3], bd[2], bd[1], bd[0]);
2398
2399 templen = fast_expansion_sum_zeroelim(4, cd, 4, da, temp8);
2400 cdalen = fast_expansion_sum_zeroelim(templen, temp8, 4, ac, cda);
2401 templen = fast_expansion_sum_zeroelim(4, da, 4, ab, temp8);
2402 dablen = fast_expansion_sum_zeroelim(templen, temp8, 4, bd, dab);
2403 for (i = 0; i < 4; i++) {
2404 bd[i] = -bd[i];
2405 ac[i] = -ac[i];
2406 }
2407 templen = fast_expansion_sum_zeroelim(4, ab, 4, bc, temp8);
2408 abclen = fast_expansion_sum_zeroelim(templen, temp8, 4, ac, abc);
2409 templen = fast_expansion_sum_zeroelim(4, bc, 4, cd, temp8);
2410 bcdlen = fast_expansion_sum_zeroelim(templen, temp8, 4, bd, bcd);
2411
2412 xlen = scale_expansion_zeroelim(bcdlen, bcd, pa[0], det24x);
2413 xlen = scale_expansion_zeroelim(xlen, det24x, pa[0], det48x);
2414 ylen = scale_expansion_zeroelim(bcdlen, bcd, pa[1], det24y);
2415 ylen = scale_expansion_zeroelim(ylen, det24y, pa[1], det48y);
2416 alen = fast_expansion_sum_zeroelim(xlen, det48x, ylen, det48y, adet);
2417
2418 xlen = scale_expansion_zeroelim(cdalen, cda, pb[0], det24x);
2419 xlen = scale_expansion_zeroelim(xlen, det24x, -pb[0], det48x);
2420 ylen = scale_expansion_zeroelim(cdalen, cda, pb[1], det24y);
2421 ylen = scale_expansion_zeroelim(ylen, det24y, -pb[1], det48y);
2422 blen = fast_expansion_sum_zeroelim(xlen, det48x, ylen, det48y, bdet);
2423
2424 xlen = scale_expansion_zeroelim(dablen, dab, pc[0], det24x);
2425 xlen = scale_expansion_zeroelim(xlen, det24x, pc[0], det48x);
2426 ylen = scale_expansion_zeroelim(dablen, dab, pc[1], det24y);
2427 ylen = scale_expansion_zeroelim(ylen, det24y, pc[1], det48y);
2428 clen = fast_expansion_sum_zeroelim(xlen, det48x, ylen, det48y, cdet);
2429
2430 xlen = scale_expansion_zeroelim(abclen, abc, pd[0], det24x);
2431 xlen = scale_expansion_zeroelim(xlen, det24x, -pd[0], det48x);
2432 ylen = scale_expansion_zeroelim(abclen, abc, pd[1], det24y);
2433 ylen = scale_expansion_zeroelim(ylen, det24y, -pd[1], det48y);
2434 dlen = fast_expansion_sum_zeroelim(xlen, det48x, ylen, det48y, ddet);
2435
2436 ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
2437 cdlen = fast_expansion_sum_zeroelim(clen, cdet, dlen, ddet, cddet);
2438 deterlen = fast_expansion_sum_zeroelim(ablen, abdet, cdlen, cddet, deter);
2439
2440 return deter[deterlen - 1];
2441 }
2442
2443 REAL incircleslow(REAL *pa, REAL *pb, REAL *pc, REAL *pd)
2444 {
2445 INEXACT REAL adx, bdx, cdx, ady, bdy, cdy;
2446 REAL adxtail, bdxtail, cdxtail;
2447 REAL adytail, bdytail, cdytail;
2448 REAL negate, negatetail;
2449 INEXACT REAL axby7, bxcy7, axcy7, bxay7, cxby7, cxay7;
2450 REAL axby[8], bxcy[8], axcy[8], bxay[8], cxby[8], cxay[8];
2451 REAL temp16[16];
2452 int temp16len;
2453 REAL detx[32], detxx[64], detxt[32], detxxt[64], detxtxt[64];
2454 int xlen, xxlen, xtlen, xxtlen, xtxtlen;
2455 REAL x1[128], x2[192];
2456 int x1len, x2len;
2457 REAL dety[32], detyy[64], detyt[32], detyyt[64], detytyt[64];
2458 int ylen, yylen, ytlen, yytlen, ytytlen;
2459 REAL y1[128], y2[192];
2460 int y1len, y2len;
2461 REAL adet[384], bdet[384], cdet[384], abdet[768], deter[1152];
2462 int alen, blen, clen, ablen, deterlen;
2463 int i;
2464
2465 INEXACT REAL bvirt;
2466 REAL avirt, bround, around;
2467 INEXACT REAL c;
2468 INEXACT REAL abig;
2469 REAL a0hi, a0lo, a1hi, a1lo, bhi, blo;
2470 REAL err1, err2, err3;
2471 INEXACT REAL _i, _j, _k, _l, _m, _n;
2472 REAL _0, _1, _2;
2473
2474 Two_Diff(pa[0], pd[0], adx, adxtail);
2475 Two_Diff(pa[1], pd[1], ady, adytail);
2476 Two_Diff(pb[0], pd[0], bdx, bdxtail);
2477 Two_Diff(pb[1], pd[1], bdy, bdytail);
2478 Two_Diff(pc[0], pd[0], cdx, cdxtail);
2479 Two_Diff(pc[1], pd[1], cdy, cdytail);
2480
2481 Two_Two_Product(adx, adxtail, bdy, bdytail,
2482 axby7, axby[6], axby[5], axby[4],
2483 axby[3], axby[2], axby[1], axby[0]);
2484 axby[7] = axby7;
2485 negate = -ady;
2486 negatetail = -adytail;
2487 Two_Two_Product(bdx, bdxtail, negate, negatetail,
2488 bxay7, bxay[6], bxay[5], bxay[4],
2489 bxay[3], bxay[2], bxay[1], bxay[0]);
2490 bxay[7] = bxay7;
2491 Two_Two_Product(bdx, bdxtail, cdy, cdytail,
2492 bxcy7, bxcy[6], bxcy[5], bxcy[4],
2493 bxcy[3], bxcy[2], bxcy[1], bxcy[0]);
2494 bxcy[7] = bxcy7;
2495 negate = -bdy;
2496 negatetail = -bdytail;
2497 Two_Two_Product(cdx, cdxtail, negate, negatetail,
2498 cxby7, cxby[6], cxby[5], cxby[4],
2499 cxby[3], cxby[2], cxby[1], cxby[0]);
2500 cxby[7] = cxby7;
2501 Two_Two_Product(cdx, cdxtail, ady, adytail,
2502 cxay7, cxay[6], cxay[5], cxay[4],
2503 cxay[3], cxay[2], cxay[1], cxay[0]);
2504 cxay[7] = cxay7;
2505 negate = -cdy;
2506 negatetail = -cdytail;
2507 Two_Two_Product(adx, adxtail, negate, negatetail,
2508 axcy7, axcy[6], axcy[5], axcy[4],
2509 axcy[3], axcy[2], axcy[1], axcy[0]);
2510 axcy[7] = axcy7;
2511
2512
2513 temp16len = fast_expansion_sum_zeroelim(8, bxcy, 8, cxby, temp16);
2514
2515 xlen = scale_expansion_zeroelim(temp16len, temp16, adx, detx);
2516 xxlen = scale_expansion_zeroelim(xlen, detx, adx, detxx);
2517 xtlen = scale_expansion_zeroelim(temp16len, temp16, adxtail, detxt);
2518 xxtlen = scale_expansion_zeroelim(xtlen, detxt, adx, detxxt);
2519 for (i = 0; i < xxtlen; i++) {
2520 detxxt[i] *= 2.0;
2521 }
2522 xtxtlen = scale_expansion_zeroelim(xtlen, detxt, adxtail, detxtxt);
2523 x1len = fast_expansion_sum_zeroelim(xxlen, detxx, xxtlen, detxxt, x1);
2524 x2len = fast_expansion_sum_zeroelim(x1len, x1, xtxtlen, detxtxt, x2);
2525
2526 ylen = scale_expansion_zeroelim(temp16len, temp16, ady, dety);
2527 yylen = scale_expansion_zeroelim(ylen, dety, ady, detyy);
2528 ytlen = scale_expansion_zeroelim(temp16len, temp16, adytail, detyt);
2529 yytlen = scale_expansion_zeroelim(ytlen, detyt, ady, detyyt);
2530 for (i = 0; i < yytlen; i++) {
2531 detyyt[i] *= 2.0;
2532 }
2533 ytytlen = scale_expansion_zeroelim(ytlen, detyt, adytail, detytyt);
2534 y1len = fast_expansion_sum_zeroelim(yylen, detyy, yytlen, detyyt, y1);
2535 y2len = fast_expansion_sum_zeroelim(y1len, y1, ytytlen, detytyt, y2);
2536
2537 alen = fast_expansion_sum_zeroelim(x2len, x2, y2len, y2, adet);
2538
2539
2540 temp16len = fast_expansion_sum_zeroelim(8, cxay, 8, axcy, temp16);
2541
2542 xlen = scale_expansion_zeroelim(temp16len, temp16, bdx, detx);
2543 xxlen = scale_expansion_zeroelim(xlen, detx, bdx, detxx);
2544 xtlen = scale_expansion_zeroelim(temp16len, temp16, bdxtail, detxt);
2545 xxtlen = scale_expansion_zeroelim(xtlen, detxt, bdx, detxxt);
2546 for (i = 0; i < xxtlen; i++) {
2547 detxxt[i] *= 2.0;
2548 }
2549 xtxtlen = scale_expansion_zeroelim(xtlen, detxt, bdxtail, detxtxt);
2550 x1len = fast_expansion_sum_zeroelim(xxlen, detxx, xxtlen, detxxt, x1);
2551 x2len = fast_expansion_sum_zeroelim(x1len, x1, xtxtlen, detxtxt, x2);
2552
2553 ylen = scale_expansion_zeroelim(temp16len, temp16, bdy, dety);
2554 yylen = scale_expansion_zeroelim(ylen, dety, bdy, detyy);
2555 ytlen = scale_expansion_zeroelim(temp16len, temp16, bdytail, detyt);
2556 yytlen = scale_expansion_zeroelim(ytlen, detyt, bdy, detyyt);
2557 for (i = 0; i < yytlen; i++) {
2558 detyyt[i] *= 2.0;
2559 }
2560 ytytlen = scale_expansion_zeroelim(ytlen, detyt, bdytail, detytyt);
2561 y1len = fast_expansion_sum_zeroelim(yylen, detyy, yytlen, detyyt, y1);
2562 y2len = fast_expansion_sum_zeroelim(y1len, y1, ytytlen, detytyt, y2);
2563
2564 blen = fast_expansion_sum_zeroelim(x2len, x2, y2len, y2, bdet);
2565
2566
2567 temp16len = fast_expansion_sum_zeroelim(8, axby, 8, bxay, temp16);
2568
2569 xlen = scale_expansion_zeroelim(temp16len, temp16, cdx, detx);
2570 xxlen = scale_expansion_zeroelim(xlen, detx, cdx, detxx);
2571 xtlen = scale_expansion_zeroelim(temp16len, temp16, cdxtail, detxt);
2572 xxtlen = scale_expansion_zeroelim(xtlen, detxt, cdx, detxxt);
2573 for (i = 0; i < xxtlen; i++) {
2574 detxxt[i] *= 2.0;
2575 }
2576 xtxtlen = scale_expansion_zeroelim(xtlen, detxt, cdxtail, detxtxt);
2577 x1len = fast_expansion_sum_zeroelim(xxlen, detxx, xxtlen, detxxt, x1);
2578 x2len = fast_expansion_sum_zeroelim(x1len, x1, xtxtlen, detxtxt, x2);
2579
2580 ylen = scale_expansion_zeroelim(temp16len, temp16, cdy, dety);
2581 yylen = scale_expansion_zeroelim(ylen, dety, cdy, detyy);
2582 ytlen = scale_expansion_zeroelim(temp16len, temp16, cdytail, detyt);
2583 yytlen = scale_expansion_zeroelim(ytlen, detyt, cdy, detyyt);
2584 for (i = 0; i < yytlen; i++) {
2585 detyyt[i] *= 2.0;
2586 }
2587 ytytlen = scale_expansion_zeroelim(ytlen, detyt, cdytail, detytyt);
2588 y1len = fast_expansion_sum_zeroelim(yylen, detyy, yytlen, detyyt, y1);
2589 y2len = fast_expansion_sum_zeroelim(y1len, y1, ytytlen, detytyt, y2);
2590
2591 clen = fast_expansion_sum_zeroelim(x2len, x2, y2len, y2, cdet);
2592
2593 ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
2594 deterlen = fast_expansion_sum_zeroelim(ablen, abdet, clen, cdet, deter);
2595
2596 return deter[deterlen - 1];
2597 }
2598
2599 REAL incircleadapt(REAL *pa, REAL *pb, REAL *pc, REAL *pd, REAL permanent)
2600 {
2601 INEXACT REAL adx, bdx, cdx, ady, bdy, cdy;
2602 REAL det, errbound;
2603
2604 INEXACT REAL bdxcdy1, cdxbdy1, cdxady1, adxcdy1, adxbdy1, bdxady1;
2605 REAL bdxcdy0, cdxbdy0, cdxady0, adxcdy0, adxbdy0, bdxady0;
2606 REAL bc[4], ca[4], ab[4];
2607 INEXACT REAL bc3, ca3, ab3;
2608 REAL axbc[8], axxbc[16], aybc[8], ayybc[16], adet[32];
2609 int axbclen, axxbclen, aybclen, ayybclen, alen;
2610 REAL bxca[8], bxxca[16], byca[8], byyca[16], bdet[32];
2611 int bxcalen, bxxcalen, bycalen, byycalen, blen;
2612 REAL cxab[8], cxxab[16], cyab[8], cyyab[16], cdet[32];
2613 int cxablen, cxxablen, cyablen, cyyablen, clen;
2614 REAL abdet[64];
2615 int ablen;
2616 REAL fin1[1152], fin2[1152];
2617 REAL *finnow, *finother, *finswap;
2618 int finlength;
2619
2620 REAL adxtail, bdxtail, cdxtail, adytail, bdytail, cdytail;
2621 INEXACT REAL adxadx1, adyady1, bdxbdx1, bdybdy1, cdxcdx1, cdycdy1;
2622 REAL adxadx0, adyady0, bdxbdx0, bdybdy0, cdxcdx0, cdycdy0;
2623 REAL aa[4], bb[4], cc[4];
2624 INEXACT REAL aa3, bb3, cc3;
2625 INEXACT REAL ti1, tj1;
2626 REAL ti0, tj0;
2627 REAL u[4], v[4];
2628 INEXACT REAL u3, v3;
2629 REAL temp8[8], temp16a[16], temp16b[16], temp16c[16];
2630 REAL temp32a[32], temp32b[32], temp48[48], temp64[64];
2631 int temp8len, temp16alen, temp16blen, temp16clen;
2632 int temp32alen, temp32blen, temp48len, temp64len;
2633 REAL axtbb[8], axtcc[8], aytbb[8], aytcc[8];
2634 int axtbblen, axtcclen, aytbblen, aytcclen;
2635 REAL bxtaa[8], bxtcc[8], bytaa[8], bytcc[8];
2636 int bxtaalen, bxtcclen, bytaalen, bytcclen;
2637 REAL cxtaa[8], cxtbb[8], cytaa[8], cytbb[8];
2638 int cxtaalen, cxtbblen, cytaalen, cytbblen;
2639 REAL axtbc[8], aytbc[8], bxtca[8], bytca[8], cxtab[8], cytab[8];
2640 int axtbclen, aytbclen, bxtcalen, bytcalen, cxtablen, cytablen;
2641 REAL axtbct[16], aytbct[16], bxtcat[16], bytcat[16], cxtabt[16], cytabt[16];
2642 int axtbctlen, aytbctlen, bxtcatlen, bytcatlen, cxtabtlen, cytabtlen;
2643 REAL axtbctt[8], aytbctt[8], bxtcatt[8];
2644 REAL bytcatt[8], cxtabtt[8], cytabtt[8];
2645 int axtbcttlen, aytbcttlen, bxtcattlen, bytcattlen, cxtabttlen, cytabttlen;
2646 REAL abt[8], bct[8], cat[8];
2647 int abtlen, bctlen, catlen;
2648 REAL abtt[4], bctt[4], catt[4];
2649 int abttlen, bcttlen, cattlen;
2650 INEXACT REAL abtt3, bctt3, catt3;
2651 REAL negate;
2652
2653 INEXACT REAL bvirt;
2654 REAL avirt, bround, around;
2655 INEXACT REAL c;
2656 INEXACT REAL abig;
2657 REAL ahi, alo, bhi, blo;
2658 REAL err1, err2, err3;
2659 INEXACT REAL _i, _j;
2660 REAL _0;
2661
2662 adx = (REAL) (pa[0] - pd[0]);
2663 bdx = (REAL) (pb[0] - pd[0]);
2664 cdx = (REAL) (pc[0] - pd[0]);
2665 ady = (REAL) (pa[1] - pd[1]);
2666 bdy = (REAL) (pb[1] - pd[1]);
2667 cdy = (REAL) (pc[1] - pd[1]);
2668
2669 Two_Product(bdx, cdy, bdxcdy1, bdxcdy0);
2670 Two_Product(cdx, bdy, cdxbdy1, cdxbdy0);
2671 Two_Two_Diff(bdxcdy1, bdxcdy0, cdxbdy1, cdxbdy0, bc3, bc[2], bc[1], bc[0]);
2672 bc[3] = bc3;
2673 axbclen = scale_expansion_zeroelim(4, bc, adx, axbc);
2674 axxbclen = scale_expansion_zeroelim(axbclen, axbc, adx, axxbc);
2675 aybclen = scale_expansion_zeroelim(4, bc, ady, aybc);
2676 ayybclen = scale_expansion_zeroelim(aybclen, aybc, ady, ayybc);
2677 alen = fast_expansion_sum_zeroelim(axxbclen, axxbc, ayybclen, ayybc, adet);
2678
2679 Two_Product(cdx, ady, cdxady1, cdxady0);
2680 Two_Product(adx, cdy, adxcdy1, adxcdy0);
2681 Two_Two_Diff(cdxady1, cdxady0, adxcdy1, adxcdy0, ca3, ca[2], ca[1], ca[0]);
2682 ca[3] = ca3;
2683 bxcalen = scale_expansion_zeroelim(4, ca, bdx, bxca);
2684 bxxcalen = scale_expansion_zeroelim(bxcalen, bxca, bdx, bxxca);
2685 bycalen = scale_expansion_zeroelim(4, ca, bdy, byca);
2686 byycalen = scale_expansion_zeroelim(bycalen, byca, bdy, byyca);
2687 blen = fast_expansion_sum_zeroelim(bxxcalen, bxxca, byycalen, byyca, bdet);
2688
2689 Two_Product(adx, bdy, adxbdy1, adxbdy0);
2690 Two_Product(bdx, ady, bdxady1, bdxady0);
2691 Two_Two_Diff(adxbdy1, adxbdy0, bdxady1, bdxady0, ab3, ab[2], ab[1], ab[0]);
2692 ab[3] = ab3;
2693 cxablen = scale_expansion_zeroelim(4, ab, cdx, cxab);
2694 cxxablen = scale_expansion_zeroelim(cxablen, cxab, cdx, cxxab);
2695 cyablen = scale_expansion_zeroelim(4, ab, cdy, cyab);
2696 cyyablen = scale_expansion_zeroelim(cyablen, cyab, cdy, cyyab);
2697 clen = fast_expansion_sum_zeroelim(cxxablen, cxxab, cyyablen, cyyab, cdet);
2698
2699 ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
2700 finlength = fast_expansion_sum_zeroelim(ablen, abdet, clen, cdet, fin1);
2701
2702 det = estimate(finlength, fin1);
2703 errbound = iccerrboundB * permanent;
2704 if ((det >= errbound) || (-det >= errbound)) {
2705 return det;
2706 }
2707
2708 Two_Diff_Tail(pa[0], pd[0], adx, adxtail);
2709 Two_Diff_Tail(pa[1], pd[1], ady, adytail);
2710 Two_Diff_Tail(pb[0], pd[0], bdx, bdxtail);
2711 Two_Diff_Tail(pb[1], pd[1], bdy, bdytail);
2712 Two_Diff_Tail(pc[0], pd[0], cdx, cdxtail);
2713 Two_Diff_Tail(pc[1], pd[1], cdy, cdytail);
2714 if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0)
2715 && (adytail == 0.0) && (bdytail == 0.0) && (cdytail == 0.0)) {
2716 return det;
2717 }
2718
2719 errbound = iccerrboundC * permanent + resulterrbound * Absolute(det);
2720 det += ((adx * adx + ady * ady) * ((bdx * cdytail + cdy * bdxtail)
2721 - (bdy * cdxtail + cdx * bdytail))
2722 + 2.0 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx))
2723 + ((bdx * bdx + bdy * bdy) * ((cdx * adytail + ady * cdxtail)
2724 - (cdy * adxtail + adx * cdytail))
2725 + 2.0 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx))
2726 + ((cdx * cdx + cdy * cdy) * ((adx * bdytail + bdy * adxtail)
2727 - (ady * bdxtail + bdx * adytail))
2728 + 2.0 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx));
2729 if ((det >= errbound) || (-det >= errbound)) {
2730 return det;
2731 }
2732
2733 finnow = fin1;
2734 finother = fin2;
2735
2736 if ((bdxtail != 0.0) || (bdytail != 0.0)
2737 || (cdxtail != 0.0) || (cdytail != 0.0)) {
2738 Square(adx, adxadx1, adxadx0);
2739 Square(ady, adyady1, adyady0);
2740 Two_Two_Sum(adxadx1, adxadx0, adyady1, adyady0, aa3, aa[2], aa[1], aa[0]);
2741 aa[3] = aa3;
2742 }
2743 if ((cdxtail != 0.0) || (cdytail != 0.0)
2744 || (adxtail != 0.0) || (adytail != 0.0)) {
2745 Square(bdx, bdxbdx1, bdxbdx0);
2746 Square(bdy, bdybdy1, bdybdy0);
2747 Two_Two_Sum(bdxbdx1, bdxbdx0, bdybdy1, bdybdy0, bb3, bb[2], bb[1], bb[0]);
2748 bb[3] = bb3;
2749 }
2750 if ((adxtail != 0.0) || (adytail != 0.0)
2751 || (bdxtail != 0.0) || (bdytail != 0.0)) {
2752 Square(cdx, cdxcdx1, cdxcdx0);
2753 Square(cdy, cdycdy1, cdycdy0);
2754 Two_Two_Sum(cdxcdx1, cdxcdx0, cdycdy1, cdycdy0, cc3, cc[2], cc[1], cc[0]);
2755 cc[3] = cc3;
2756 }
2757
2758 if (adxtail != 0.0) {
2759 axtbclen = scale_expansion_zeroelim(4, bc, adxtail, axtbc);
2760 temp16alen = scale_expansion_zeroelim(axtbclen, axtbc, 2.0 * adx,
2761 temp16a);
2762
2763 axtcclen = scale_expansion_zeroelim(4, cc, adxtail, axtcc);
2764 temp16blen = scale_expansion_zeroelim(axtcclen, axtcc, bdy, temp16b);
2765
2766 axtbblen = scale_expansion_zeroelim(4, bb, adxtail, axtbb);
2767 temp16clen = scale_expansion_zeroelim(axtbblen, axtbb, -cdy, temp16c);
2768
2769 temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a,
2770 temp16blen, temp16b, temp32a);
2771 temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c,
2772 temp32alen, temp32a, temp48);
2773 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len,
2774 temp48, finother);
2775 finswap = finnow; finnow = finother; finother = finswap;
2776 }
2777 if (adytail != 0.0) {
2778 aytbclen = scale_expansion_zeroelim(4, bc, adytail, aytbc);
2779 temp16alen = scale_expansion_zeroelim(aytbclen, aytbc, 2.0 * ady,
2780 temp16a);
2781
2782 aytbblen = scale_expansion_zeroelim(4, bb, adytail, aytbb);
2783 temp16blen = scale_expansion_zeroelim(aytbblen, aytbb, cdx, temp16b);
2784
2785 aytcclen = scale_expansion_zeroelim(4, cc, adytail, aytcc);
2786 temp16clen = scale_expansion_zeroelim(aytcclen, aytcc, -bdx, temp16c);
2787
2788 temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a,
2789 temp16blen, temp16b, temp32a);
2790 temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c,
2791 temp32alen, temp32a, temp48);
2792 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len,
2793 temp48, finother);
2794 finswap = finnow; finnow = finother; finother = finswap;
2795 }
2796 if (bdxtail != 0.0) {
2797 bxtcalen = scale_expansion_zeroelim(4, ca, bdxtail, bxtca);
2798 temp16alen = scale_expansion_zeroelim(bxtcalen, bxtca, 2.0 * bdx,
2799 temp16a);
2800
2801 bxtaalen = scale_expansion_zeroelim(4, aa, bdxtail, bxtaa);
2802 temp16blen = scale_expansion_zeroelim(bxtaalen, bxtaa, cdy, temp16b);
2803
2804 bxtcclen = scale_expansion_zeroelim(4, cc, bdxtail, bxtcc);
2805 temp16clen = scale_expansion_zeroelim(bxtcclen, bxtcc, -ady, temp16c);
2806
2807 temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a,
2808 temp16blen, temp16b, temp32a);
2809 temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c,
2810 temp32alen, temp32a, temp48);
2811 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len,
2812 temp48, finother);
2813 finswap = finnow; finnow = finother; finother = finswap;
2814 }
2815 if (bdytail != 0.0) {
2816 bytcalen = scale_expansion_zeroelim(4, ca, bdytail, bytca);
2817 temp16alen = scale_expansion_zeroelim(bytcalen, bytca, 2.0 * bdy,
2818 temp16a);
2819
2820 bytcclen = scale_expansion_zeroelim(4, cc, bdytail, bytcc);
2821 temp16blen = scale_expansion_zeroelim(bytcclen, bytcc, adx, temp16b);
2822
2823 bytaalen = scale_expansion_zeroelim(4, aa, bdytail, bytaa);
2824 temp16clen = scale_expansion_zeroelim(bytaalen, bytaa, -cdx, temp16c);
2825
2826 temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a,
2827 temp16blen, temp16b, temp32a);
2828 temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c,
2829 temp32alen, temp32a, temp48);
2830 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len,
2831 temp48, finother);
2832 finswap = finnow; finnow = finother; finother = finswap;
2833 }
2834 if (cdxtail != 0.0) {
2835 cxtablen = scale_expansion_zeroelim(4, ab, cdxtail, cxtab);
2836 temp16alen = scale_expansion_zeroelim(cxtablen, cxtab, 2.0 * cdx,
2837 temp16a);
2838
2839 cxtbblen = scale_expansion_zeroelim(4, bb, cdxtail, cxtbb);
2840 temp16blen = scale_expansion_zeroelim(cxtbblen, cxtbb, ady, temp16b);
2841
2842 cxtaalen = scale_expansion_zeroelim(4, aa, cdxtail, cxtaa);
2843 temp16clen = scale_expansion_zeroelim(cxtaalen, cxtaa, -bdy, temp16c);
2844
2845 temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a,
2846 temp16blen, temp16b, temp32a);
2847 temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c,
2848 temp32alen, temp32a, temp48);
2849 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len,
2850 temp48, finother);
2851 finswap = finnow; finnow = finother; finother = finswap;
2852 }
2853 if (cdytail != 0.0) {
2854 cytablen = scale_expansion_zeroelim(4, ab, cdytail, cytab);
2855 temp16alen = scale_expansion_zeroelim(cytablen, cytab, 2.0 * cdy,
2856 temp16a);
2857
2858 cytaalen = scale_expansion_zeroelim(4, aa, cdytail, cytaa);
2859 temp16blen = scale_expansion_zeroelim(cytaalen, cytaa, bdx, temp16b);
2860
2861 cytbblen = scale_expansion_zeroelim(4, bb, cdytail, cytbb);
2862 temp16clen = scale_expansion_zeroelim(cytbblen, cytbb, -adx, temp16c);
2863
2864 temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a,
2865 temp16blen, temp16b, temp32a);
2866 temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c,
2867 temp32alen, temp32a, temp48);
2868 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len,
2869 temp48, finother);
2870 finswap = finnow; finnow = finother; finother = finswap;
2871 }
2872
2873 if ((adxtail != 0.0) || (adytail != 0.0)) {
2874 if ((bdxtail != 0.0) || (bdytail != 0.0)
2875 || (cdxtail != 0.0) || (cdytail != 0.0)) {
2876 Two_Product(bdxtail, cdy, ti1, ti0);
2877 Two_Product(bdx, cdytail, tj1, tj0);
2878 Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
2879 u[3] = u3;
2880 negate = -bdy;
2881 Two_Product(cdxtail, negate, ti1, ti0);
2882 negate = -bdytail;
2883 Two_Product(cdx, negate, tj1, tj0);
2884 Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
2885 v[3] = v3;
2886 bctlen = fast_expansion_sum_zeroelim(4, u, 4, v, bct);
2887
2888 Two_Product(bdxtail, cdytail, ti1, ti0);
2889 Two_Product(cdxtail, bdytail, tj1, tj0);
2890 Two_Two_Diff(ti1, ti0, tj1, tj0, bctt3, bctt[2], bctt[1], bctt[0]);
2891 bctt[3] = bctt3;
2892 bcttlen = 4;
2893 } else {
2894 bct[0] = 0.0;
2895 bctlen = 1;
2896 bctt[0] = 0.0;
2897 bcttlen = 1;
2898 }
2899
2900 if (adxtail != 0.0) {
2901 temp16alen = scale_expansion_zeroelim(axtbclen, axtbc, adxtail, temp16a);
2902 axtbctlen = scale_expansion_zeroelim(bctlen, bct, adxtail, axtbct);
2903 temp32alen = scale_expansion_zeroelim(axtbctlen, axtbct, 2.0 * adx,
2904 temp32a);
2905 temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a,
2906 temp32alen, temp32a, temp48);
2907 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len,
2908 temp48, finother);
2909 finswap = finnow; finnow = finother; finother = finswap;
2910 if (bdytail != 0.0) {
2911 temp8len = scale_expansion_zeroelim(4, cc, adxtail, temp8);
2912 temp16alen = scale_expansion_zeroelim(temp8len, temp8, bdytail,
2913 temp16a);
2914 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen,
2915 temp16a, finother);
2916 finswap = finnow; finnow = finother; finother = finswap;
2917 }
2918 if (cdytail != 0.0) {
2919 temp8len = scale_expansion_zeroelim(4, bb, -adxtail, temp8);
2920 temp16alen = scale_expansion_zeroelim(temp8len, temp8, cdytail,
2921 temp16a);
2922 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen,
2923 temp16a, finother);
2924 finswap = finnow; finnow = finother; finother = finswap;
2925 }
2926
2927 temp32alen = scale_expansion_zeroelim(axtbctlen, axtbct, adxtail,
2928 temp32a);
2929 axtbcttlen = scale_expansion_zeroelim(bcttlen, bctt, adxtail, axtbctt);
2930 temp16alen = scale_expansion_zeroelim(axtbcttlen, axtbctt, 2.0 * adx,
2931 temp16a);
2932 temp16blen = scale_expansion_zeroelim(axtbcttlen, axtbctt, adxtail,
2933 temp16b);
2934 temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a,
2935 temp16blen, temp16b, temp32b);
2936 temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a,
2937 temp32blen, temp32b, temp64);
2938 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len,
2939 temp64, finother);
2940 finswap = finnow; finnow = finother; finother = finswap;
2941 }
2942 if (adytail != 0.0) {
2943 temp16alen = scale_expansion_zeroelim(aytbclen, aytbc, adytail, temp16a);
2944 aytbctlen = scale_expansion_zeroelim(bctlen, bct, adytail, aytbct);
2945 temp32alen = scale_expansion_zeroelim(aytbctlen, aytbct, 2.0 * ady,
2946 temp32a);
2947 temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a,
2948 temp32alen, temp32a, temp48);
2949 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len,
2950 temp48, finother);
2951 finswap = finnow; finnow = finother; finother = finswap;
2952
2953
2954 temp32alen = scale_expansion_zeroelim(aytbctlen, aytbct, adytail,
2955 temp32a);
2956 aytbcttlen = scale_expansion_zeroelim(bcttlen, bctt, adytail, aytbctt);
2957 temp16alen = scale_expansion_zeroelim(aytbcttlen, aytbctt, 2.0 * ady,
2958 temp16a);
2959 temp16blen = scale_expansion_zeroelim(aytbcttlen, aytbctt, adytail,
2960 temp16b);
2961 temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a,
2962 temp16blen, temp16b, temp32b);
2963 temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a,
2964 temp32blen, temp32b, temp64);
2965 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len,
2966 temp64, finother);
2967 finswap = finnow; finnow = finother; finother = finswap;
2968 }
2969 }
2970 if ((bdxtail != 0.0) || (bdytail != 0.0)) {
2971 if ((cdxtail != 0.0) || (cdytail != 0.0)
2972 || (adxtail != 0.0) || (adytail != 0.0)) {
2973 Two_Product(cdxtail, ady, ti1, ti0);
2974 Two_Product(cdx, adytail, tj1, tj0);
2975 Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
2976 u[3] = u3;
2977 negate = -cdy;
2978 Two_Product(adxtail, negate, ti1, ti0);
2979 negate = -cdytail;
2980 Two_Product(adx, negate, tj1, tj0);
2981 Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
2982 v[3] = v3;
2983 catlen = fast_expansion_sum_zeroelim(4, u, 4, v, cat);
2984
2985 Two_Product(cdxtail, adytail, ti1, ti0);
2986 Two_Product(adxtail, cdytail, tj1, tj0);
2987 Two_Two_Diff(ti1, ti0, tj1, tj0, catt3, catt[2], catt[1], catt[0]);
2988 catt[3] = catt3;
2989 cattlen = 4;
2990 } else {
2991 cat[0] = 0.0;
2992 catlen = 1;
2993 catt[0] = 0.0;
2994 cattlen = 1;
2995 }
2996
2997 if (bdxtail != 0.0) {
2998 temp16alen = scale_expansion_zeroelim(bxtcalen, bxtca, bdxtail, temp16a);
2999 bxtcatlen = scale_expansion_zeroelim(catlen, cat, bdxtail, bxtcat);
3000 temp32alen = scale_expansion_zeroelim(bxtcatlen, bxtcat, 2.0 * bdx,
3001 temp32a);
3002 temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a,
3003 temp32alen, temp32a, temp48);
3004 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len,
3005 temp48, finother);
3006 finswap = finnow; finnow = finother; finother = finswap;
3007 if (cdytail != 0.0) {
3008 temp8len = scale_expansion_zeroelim(4, aa, bdxtail, temp8);
3009 temp16alen = scale_expansion_zeroelim(temp8len, temp8, cdytail,
3010 temp16a);
3011 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen,
3012 temp16a, finother);
3013 finswap = finnow; finnow = finother; finother = finswap;
3014 }
3015 if (adytail != 0.0) {
3016 temp8len = scale_expansion_zeroelim(4, cc, -bdxtail, temp8);
3017 temp16alen = scale_expansion_zeroelim(temp8len, temp8, adytail,
3018 temp16a);
3019 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen,
3020 temp16a, finother);
3021 finswap = finnow; finnow = finother; finother = finswap;
3022 }
3023
3024 temp32alen = scale_expansion_zeroelim(bxtcatlen, bxtcat, bdxtail,
3025 temp32a);
3026 bxtcattlen = scale_expansion_zeroelim(cattlen, catt, bdxtail, bxtcatt);
3027 temp16alen = scale_expansion_zeroelim(bxtcattlen, bxtcatt, 2.0 * bdx,
3028 temp16a);
3029 temp16blen = scale_expansion_zeroelim(bxtcattlen, bxtcatt, bdxtail,
3030 temp16b);
3031 temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a,
3032 temp16blen, temp16b, temp32b);
3033 temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3034 temp32blen, temp32b, temp64);
3035 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len,
3036 temp64, finother);
3037 finswap = finnow; finnow = finother; finother = finswap;
3038 }
3039 if (bdytail != 0.0) {
3040 temp16alen = scale_expansion_zeroelim(bytcalen, bytca, bdytail, temp16a);
3041 bytcatlen = scale_expansion_zeroelim(catlen, cat, bdytail, bytcat);
3042 temp32alen = scale_expansion_zeroelim(bytcatlen, bytcat, 2.0 * bdy,
3043 temp32a);
3044 temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a,
3045 temp32alen, temp32a, temp48);
3046 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len,
3047 temp48, finother);
3048 finswap = finnow; finnow = finother; finother = finswap;
3049
3050
3051 temp32alen = scale_expansion_zeroelim(bytcatlen, bytcat, bdytail,
3052 temp32a);
3053 bytcattlen = scale_expansion_zeroelim(cattlen, catt, bdytail, bytcatt);
3054 temp16alen = scale_expansion_zeroelim(bytcattlen, bytcatt, 2.0 * bdy,
3055 temp16a);
3056 temp16blen = scale_expansion_zeroelim(bytcattlen, bytcatt, bdytail,
3057 temp16b);
3058 temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a,
3059 temp16blen, temp16b, temp32b);
3060 temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3061 temp32blen, temp32b, temp64);
3062 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len,
3063 temp64, finother);
3064 finswap = finnow; finnow = finother; finother = finswap;
3065 }
3066 }
3067 if ((cdxtail != 0.0) || (cdytail != 0.0)) {
3068 if ((adxtail != 0.0) || (adytail != 0.0)
3069 || (bdxtail != 0.0) || (bdytail != 0.0)) {
3070 Two_Product(adxtail, bdy, ti1, ti0);
3071 Two_Product(adx, bdytail, tj1, tj0);
3072 Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
3073 u[3] = u3;
3074 negate = -ady;
3075 Two_Product(bdxtail, negate, ti1, ti0);
3076 negate = -adytail;
3077 Two_Product(bdx, negate, tj1, tj0);
3078 Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
3079 v[3] = v3;
3080 abtlen = fast_expansion_sum_zeroelim(4, u, 4, v, abt);
3081
3082 Two_Product(adxtail, bdytail, ti1, ti0);
3083 Two_Product(bdxtail, adytail, tj1, tj0);
3084 Two_Two_Diff(ti1, ti0, tj1, tj0, abtt3, abtt[2], abtt[1], abtt[0]);
3085 abtt[3] = abtt3;
3086 abttlen = 4;
3087 } else {
3088 abt[0] = 0.0;
3089 abtlen = 1;
3090 abtt[0] = 0.0;
3091 abttlen = 1;
3092 }
3093
3094 if (cdxtail != 0.0) {
3095 temp16alen = scale_expansion_zeroelim(cxtablen, cxtab, cdxtail, temp16a);
3096 cxtabtlen = scale_expansion_zeroelim(abtlen, abt, cdxtail, cxtabt);
3097 temp32alen = scale_expansion_zeroelim(cxtabtlen, cxtabt, 2.0 * cdx,
3098 temp32a);
3099 temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a,
3100 temp32alen, temp32a, temp48);
3101 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len,
3102 temp48, finother);
3103 finswap = finnow; finnow = finother; finother = finswap;
3104 if (adytail != 0.0) {
3105 temp8len = scale_expansion_zeroelim(4, bb, cdxtail, temp8);
3106 temp16alen = scale_expansion_zeroelim(temp8len, temp8, adytail,
3107 temp16a);
3108 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen,
3109 temp16a, finother);
3110 finswap = finnow; finnow = finother; finother = finswap;
3111 }
3112 if (bdytail != 0.0) {
3113 temp8len = scale_expansion_zeroelim(4, aa, -cdxtail, temp8);
3114 temp16alen = scale_expansion_zeroelim(temp8len, temp8, bdytail,
3115 temp16a);
3116 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen,
3117 temp16a, finother);
3118 finswap = finnow; finnow = finother; finother = finswap;
3119 }
3120
3121 temp32alen = scale_expansion_zeroelim(cxtabtlen, cxtabt, cdxtail,
3122 temp32a);
3123 cxtabttlen = scale_expansion_zeroelim(abttlen, abtt, cdxtail, cxtabtt);
3124 temp16alen = scale_expansion_zeroelim(cxtabttlen, cxtabtt, 2.0 * cdx,
3125 temp16a);
3126 temp16blen = scale_expansion_zeroelim(cxtabttlen, cxtabtt, cdxtail,
3127 temp16b);
3128 temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a,
3129 temp16blen, temp16b, temp32b);
3130 temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3131 temp32blen, temp32b, temp64);
3132 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len,
3133 temp64, finother);
3134 finswap = finnow; finnow = finother; finother = finswap;
3135 }
3136 if (cdytail != 0.0) {
3137 temp16alen = scale_expansion_zeroelim(cytablen, cytab, cdytail, temp16a);
3138 cytabtlen = scale_expansion_zeroelim(abtlen, abt, cdytail, cytabt);
3139 temp32alen = scale_expansion_zeroelim(cytabtlen, cytabt, 2.0 * cdy,
3140 temp32a);
3141 temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a,
3142 temp32alen, temp32a, temp48);
3143 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len,
3144 temp48, finother);
3145 finswap = finnow; finnow = finother; finother = finswap;
3146
3147
3148 temp32alen = scale_expansion_zeroelim(cytabtlen, cytabt, cdytail,
3149 temp32a);
3150 cytabttlen = scale_expansion_zeroelim(abttlen, abtt, cdytail, cytabtt);
3151 temp16alen = scale_expansion_zeroelim(cytabttlen, cytabtt, 2.0 * cdy,
3152 temp16a);
3153 temp16blen = scale_expansion_zeroelim(cytabttlen, cytabtt, cdytail,
3154 temp16b);
3155 temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a,
3156 temp16blen, temp16b, temp32b);
3157 temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3158 temp32blen, temp32b, temp64);
3159 finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len,
3160 temp64, finother);
3161 finswap = finnow; finnow = finother; finother = finswap;
3162 }
3163 }
3164
3165 return finnow[finlength - 1];
3166 }
3167
3168 REAL incircle(REAL *pa, REAL *pb, REAL *pc, REAL *pd)
3169 {
3170 REAL adx, bdx, cdx, ady, bdy, cdy;
3171 REAL bdxcdy, cdxbdy, cdxady, adxcdy, adxbdy, bdxady;
3172 REAL alift, blift, clift;
3173 REAL det;
3174 REAL permanent, errbound;
3175
3176 adx = pa[0] - pd[0];
3177 bdx = pb[0] - pd[0];
3178 cdx = pc[0] - pd[0];
3179 ady = pa[1] - pd[1];
3180 bdy = pb[1] - pd[1];
3181 cdy = pc[1] - pd[1];
3182
3183 bdxcdy = bdx * cdy;
3184 cdxbdy = cdx * bdy;
3185 alift = adx * adx + ady * ady;
3186
3187 cdxady = cdx * ady;
3188 adxcdy = adx * cdy;
3189 blift = bdx * bdx + bdy * bdy;
3190
3191 adxbdy = adx * bdy;
3192 bdxady = bdx * ady;
3193 clift = cdx * cdx + cdy * cdy;
3194
3195 det = alift * (bdxcdy - cdxbdy)
3196 + blift * (cdxady - adxcdy)
3197 + clift * (adxbdy - bdxady);
3198
3199 permanent = (Absolute(bdxcdy) + Absolute(cdxbdy)) * alift
3200 + (Absolute(cdxady) + Absolute(adxcdy)) * blift
3201 + (Absolute(adxbdy) + Absolute(bdxady)) * clift;
3202 errbound = iccerrboundA * permanent;
3203 if ((det > errbound) || (-det > errbound)) {
3204 return det;
3205 }
3206
3207 return incircleadapt(pa, pb, pc, pd, permanent);
3208 }
3209
3210 /*****************************************************************************/
3211 /* */
3212 /* inspherefast() Approximate 3D insphere test. Nonrobust. */
3213 /* insphereexact() Exact 3D insphere test. Robust. */
3214 /* insphereslow() Another exact 3D insphere test. Robust. */
3215 /* insphere() Adaptive exact 3D insphere test. Robust. */
3216 /* */
3217 /* Return a positive value if the point pe lies inside the */
3218 /* sphere passing through pa, pb, pc, and pd; a negative value */
3219 /* if it lies outside; and zero if the five points are */
3220 /* cospherical. The points pa, pb, pc, and pd must be ordered */
3221 /* so that they have a positive orientation (as defined by */
3222 /* orient3d()), or the sign of the result will be reversed. */
3223 /* */
3224 /* Only the first and last routine should be used; the middle two are for */
3225 /* timings. */
3226 /* */
3227 /* The last three use exact arithmetic to ensure a correct answer. The */
3228 /* result returned is the determinant of a matrix. In insphere() only, */
3229 /* this determinant is computed adaptively, in the sense that exact */
3230 /* arithmetic is used only to the degree it is needed to ensure that the */
3231 /* returned value has the correct sign. Hence, insphere() is usually quite */
3232 /* fast, but will run more slowly when the input points are cospherical or */
3233 /* nearly so. */
3234 /* */
3235 /*****************************************************************************/
3236
3237 REAL inspherefast(REAL *pa, REAL *pb, REAL *pc, REAL *pd, REAL *pe)
3238 {
3239 REAL aex, bex, cex, dex;
3240 REAL aey, bey, cey, dey;
3241 REAL aez, bez, cez, dez;
3242 REAL alift, blift, clift, dlift;
3243 REAL ab, bc, cd, da, ac, bd;
3244 REAL abc, bcd, cda, dab;
3245
3246 aex = pa[0] - pe[0];
3247 bex = pb[0] - pe[0];
3248 cex = pc[0] - pe[0];
3249 dex = pd[0] - pe[0];
3250 aey = pa[1] - pe[1];
3251 bey = pb[1] - pe[1];
3252 cey = pc[1] - pe[1];
3253 dey = pd[1] - pe[1];
3254 aez = pa[2] - pe[2];
3255 bez = pb[2] - pe[2];
3256 cez = pc[2] - pe[2];
3257 dez = pd[2] - pe[2];
3258
3259 ab = aex * bey - bex * aey;
3260 bc = bex * cey - cex * bey;
3261 cd = cex * dey - dex * cey;
3262 da = dex * aey - aex * dey;
3263
3264 ac = aex * cey - cex * aey;
3265 bd = bex * dey - dex * bey;
3266
3267 abc = aez * bc - bez * ac + cez * ab;
3268 bcd = bez * cd - cez * bd + dez * bc;
3269 cda = cez * da + dez * ac + aez * cd;
3270 dab = dez * ab + aez * bd + bez * da;
3271
3272 alift = aex * aex + aey * aey + aez * aez;
3273 blift = bex * bex + bey * bey + bez * bez;
3274 clift = cex * cex + cey * cey + cez * cez;
3275 dlift = dex * dex + dey * dey + dez * dez;
3276
3277 return (dlift * abc - clift * dab) + (blift * cda - alift * bcd);
3278 }
3279
3280 REAL insphereexact(REAL *pa, REAL *pb, REAL *pc, REAL *pd, REAL *pe)
3281 {
3282 INEXACT REAL axby1, bxcy1, cxdy1, dxey1, exay1;
3283 INEXACT REAL bxay1, cxby1, dxcy1, exdy1, axey1;
3284 INEXACT REAL axcy1, bxdy1, cxey1, dxay1, exby1;
3285 INEXACT REAL cxay1, dxby1, excy1, axdy1, bxey1;
3286 REAL axby0, bxcy0, cxdy0, dxey0, exay0;
3287 REAL bxay0, cxby0, dxcy0, exdy0, axey0;
3288 REAL axcy0, bxdy0, cxey0, dxay0, exby0;
3289 REAL cxay0, dxby0, excy0, axdy0, bxey0;
3290 REAL ab[4], bc[4], cd[4], de[4], ea[4];
3291 REAL ac[4], bd[4], ce[4], da[4], eb[4];
3292 REAL temp8a[8], temp8b[8], temp16[16];
3293 int temp8alen, temp8blen, temp16len;
3294 REAL abc[24], bcd[24], cde[24], dea[24], eab[24];
3295 REAL abd[24], bce[24], cda[24], deb[24], eac[24];
3296 int abclen, bcdlen, cdelen, dealen, eablen;
3297 int abdlen, bcelen, cdalen, deblen, eaclen;
3298 REAL temp48a[48], temp48b[48];
3299 int temp48alen, temp48blen;
3300 REAL abcd[96], bcde[96], cdea[96], deab[96], eabc[96];
3301 int abcdlen, bcdelen, cdealen, deablen, eabclen;
3302 REAL temp192[192];
3303 REAL det384x[384], det384y[384], det384z[384];
3304 int xlen, ylen, zlen;
3305 REAL detxy[768];
3306 int xylen;
3307 REAL adet[1152], bdet[1152], cdet[1152], ddet[1152], edet[1152];
3308 int alen, blen, clen, dlen, elen;
3309 REAL abdet[2304], cddet[2304], cdedet[3456];
3310 int ablen, cdlen;
3311 REAL deter[5760];
3312 int deterlen;
3313 int i;
3314
3315 INEXACT REAL bvirt;
3316 REAL avirt, bround, around;
3317 INEXACT REAL c;
3318 INEXACT REAL abig;
3319 REAL ahi, alo, bhi, blo;
3320 REAL err1, err2, err3;
3321 INEXACT REAL _i, _j;
3322 REAL _0;
3323
3324 Two_Product(pa[0], pb[1], axby1, axby0);
3325 Two_Product(pb[0], pa[1], bxay1, bxay0);
3326 Two_Two_Diff(axby1, axby0, bxay1, bxay0, ab[3], ab[2], ab[1], ab[0]);
3327
3328 Two_Product(pb[0], pc[1], bxcy1, bxcy0);
3329 Two_Product(pc[0], pb[1], cxby1, cxby0);
3330 Two_Two_Diff(bxcy1, bxcy0, cxby1, cxby0, bc[3], bc[2], bc[1], bc[0]);
3331
3332 Two_Product(pc[0], pd[1], cxdy1, cxdy0);
3333 Two_Product(pd[0], pc[1], dxcy1, dxcy0);
3334 Two_Two_Diff(cxdy1, cxdy0, dxcy1, dxcy0, cd[3], cd[2], cd[1], cd[0]);
3335
3336 Two_Product(pd[0], pe[1], dxey1, dxey0);
3337 Two_Product(pe[0], pd[1], exdy1, exdy0);
3338 Two_Two_Diff(dxey1, dxey0, exdy1, exdy0, de[3], de[2], de[1], de[0]);
3339
3340 Two_Product(pe[0], pa[1], exay1, exay0);
3341 Two_Product(pa[0], pe[1], axey1, axey0);
3342 Two_Two_Diff(exay1, exay0, axey1, axey0, ea[3], ea[2], ea[1], ea[0]);
3343
3344 Two_Product(pa[0], pc[1], axcy1, axcy0);
3345 Two_Product(pc[0], pa[1], cxay1, cxay0);
3346 Two_Two_Diff(axcy1, axcy0, cxay1, cxay0, ac[3], ac[2], ac[1], ac[0]);
3347
3348 Two_Product(pb[0], pd[1], bxdy1, bxdy0);
3349 Two_Product(pd[0], pb[1], dxby1, dxby0);
3350 Two_Two_Diff(bxdy1, bxdy0, dxby1, dxby0, bd[3], bd[2], bd[1], bd[0]);
3351
3352 Two_Product(pc[0], pe[1], cxey1, cxey0);
3353 Two_Product(pe[0], pc[1], excy1, excy0);
3354 Two_Two_Diff(cxey1, cxey0, excy1, excy0, ce[3], ce[2], ce[1], ce[0]);
3355
3356 Two_Product(pd[0], pa[1], dxay1, dxay0);
3357 Two_Product(pa[0], pd[1], axdy1, axdy0);
3358 Two_Two_Diff(dxay1, dxay0, axdy1, axdy0, da[3], da[2], da[1], da[0]);
3359
3360 Two_Product(pe[0], pb[1], exby1, exby0);
3361 Two_Product(pb[0], pe[1], bxey1, bxey0);
3362 Two_Two_Diff(exby1, exby0, bxey1, bxey0, eb[3], eb[2], eb[1], eb[0]);
3363
3364 temp8alen = scale_expansion_zeroelim(4, bc, pa[2], temp8a);
3365 temp8blen = scale_expansion_zeroelim(4, ac, -pb[2], temp8b);
3366 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b,
3367 temp16);
3368 temp8alen = scale_expansion_zeroelim(4, ab, pc[2], temp8a);
3369 abclen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16,
3370 abc);
3371
3372 temp8alen = scale_expansion_zeroelim(4, cd, pb[2], temp8a);
3373 temp8blen = scale_expansion_zeroelim(4, bd, -pc[2], temp8b);
3374 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b,
3375 temp16);
3376 temp8alen = scale_expansion_zeroelim(4, bc, pd[2], temp8a);
3377 bcdlen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16,
3378 bcd);
3379
3380 temp8alen = scale_expansion_zeroelim(4, de, pc[2], temp8a);
3381 temp8blen = scale_expansion_zeroelim(4, ce, -pd[2], temp8b);
3382 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b,
3383 temp16);
3384 temp8alen = scale_expansion_zeroelim(4, cd, pe[2], temp8a);
3385 cdelen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16,
3386 cde);
3387
3388 temp8alen = scale_expansion_zeroelim(4, ea, pd[2], temp8a);
3389 temp8blen = scale_expansion_zeroelim(4, da, -pe[2], temp8b);
3390 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b,
3391 temp16);
3392 temp8alen = scale_expansion_zeroelim(4, de, pa[2], temp8a);
3393 dealen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16,
3394 dea);
3395
3396 temp8alen = scale_expansion_zeroelim(4, ab, pe[2], temp8a);
3397 temp8blen = scale_expansion_zeroelim(4, eb, -pa[2], temp8b);
3398 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b,
3399 temp16);
3400 temp8alen = scale_expansion_zeroelim(4, ea, pb[2], temp8a);
3401 eablen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16,
3402 eab);
3403
3404 temp8alen = scale_expansion_zeroelim(4, bd, pa[2], temp8a);
3405 temp8blen = scale_expansion_zeroelim(4, da, pb[2], temp8b);
3406 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b,
3407 temp16);
3408 temp8alen = scale_expansion_zeroelim(4, ab, pd[2], temp8a);
3409 abdlen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16,
3410 abd);
3411
3412 temp8alen = scale_expansion_zeroelim(4, ce, pb[2], temp8a);
3413 temp8blen = scale_expansion_zeroelim(4, eb, pc[2], temp8b);
3414 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b,
3415 temp16);
3416 temp8alen = scale_expansion_zeroelim(4, bc, pe[2], temp8a);
3417 bcelen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16,
3418 bce);
3419
3420 temp8alen = scale_expansion_zeroelim(4, da, pc[2], temp8a);
3421 temp8blen = scale_expansion_zeroelim(4, ac, pd[2], temp8b);
3422 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b,
3423 temp16);
3424 temp8alen = scale_expansion_zeroelim(4, cd, pa[2], temp8a);
3425 cdalen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16,
3426 cda);
3427
3428 temp8alen = scale_expansion_zeroelim(4, eb, pd[2], temp8a);
3429 temp8blen = scale_expansion_zeroelim(4, bd, pe[2], temp8b);
3430 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b,
3431 temp16);
3432 temp8alen = scale_expansion_zeroelim(4, de, pb[2], temp8a);
3433 deblen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16,
3434 deb);
3435
3436 temp8alen = scale_expansion_zeroelim(4, ac, pe[2], temp8a);
3437 temp8blen = scale_expansion_zeroelim(4, ce, pa[2], temp8b);
3438 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b,
3439 temp16);
3440 temp8alen = scale_expansion_zeroelim(4, ea, pc[2], temp8a);
3441 eaclen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16,
3442 eac);
3443
3444 temp48alen = fast_expansion_sum_zeroelim(cdelen, cde, bcelen, bce, temp48a);
3445 temp48blen = fast_expansion_sum_zeroelim(deblen, deb, bcdlen, bcd, temp48b);
3446 for (i = 0; i < temp48blen; i++) {
3447 temp48b[i] = -temp48b[i];
3448 }
3449 bcdelen = fast_expansion_sum_zeroelim(temp48alen, temp48a,
3450 temp48blen, temp48b, bcde);
3451 xlen = scale_expansion_zeroelim(bcdelen, bcde, pa[0], temp192);
3452 xlen = scale_expansion_zeroelim(xlen, temp192, pa[0], det384x);
3453 ylen = scale_expansion_zeroelim(bcdelen, bcde, pa[1], temp192);
3454 ylen = scale_expansion_zeroelim(ylen, temp192, pa[1], det384y);
3455 zlen = scale_expansion_zeroelim(bcdelen, bcde, pa[2], temp192);
3456 zlen = scale_expansion_zeroelim(zlen, temp192, pa[2], det384z);
3457 xylen = fast_expansion_sum_zeroelim(xlen, det384x, ylen, det384y, detxy);
3458 alen = fast_expansion_sum_zeroelim(xylen, detxy, zlen, det384z, adet);
3459
3460 temp48alen = fast_expansion_sum_zeroelim(dealen, dea, cdalen, cda, temp48a);
3461 temp48blen = fast_expansion_sum_zeroelim(eaclen, eac, cdelen, cde, temp48b);
3462 for (i = 0; i < temp48blen; i++) {
3463 temp48b[i] = -temp48b[i];
3464 }
3465 cdealen = fast_expansion_sum_zeroelim(temp48alen, temp48a,
3466 temp48blen, temp48b, cdea);
3467 xlen = scale_expansion_zeroelim(cdealen, cdea, pb[0], temp192);
3468 xlen = scale_expansion_zeroelim(xlen, temp192, pb[0], det384x);
3469 ylen = scale_expansion_zeroelim(cdealen, cdea, pb[1], temp192);
3470 ylen = scale_expansion_zeroelim(ylen, temp192, pb[1], det384y);
3471 zlen = scale_expansion_zeroelim(cdealen, cdea, pb[2], temp192);
3472 zlen = scale_expansion_zeroelim(zlen, temp192, pb[2], det384z);
3473 xylen = fast_expansion_sum_zeroelim(xlen, det384x, ylen, det384y, detxy);
3474 blen = fast_expansion_sum_zeroelim(xylen, detxy, zlen, det384z, bdet);
3475
3476 temp48alen = fast_expansion_sum_zeroelim(eablen, eab, deblen, deb, temp48a);
3477 temp48blen = fast_expansion_sum_zeroelim(abdlen, abd, dealen, dea, temp48b);
3478 for (i = 0; i < temp48blen; i++) {
3479 temp48b[i] = -temp48b[i];
3480 }
3481 deablen = fast_expansion_sum_zeroelim(temp48alen, temp48a,
3482 temp48blen, temp48b, deab);
3483 xlen = scale_expansion_zeroelim(deablen, deab, pc[0], temp192);
3484 xlen = scale_expansion_zeroelim(xlen, temp192, pc[0], det384x);
3485 ylen = scale_expansion_zeroelim(deablen, deab, pc[1], temp192);
3486 ylen = scale_expansion_zeroelim(ylen, temp192, pc[1], det384y);
3487 zlen = scale_expansion_zeroelim(deablen, deab, pc[2], temp192);
3488 zlen = scale_expansion_zeroelim(zlen, temp192, pc[2], det384z);
3489 xylen = fast_expansion_sum_zeroelim(xlen, det384x, ylen, det384y, detxy);
3490 clen = fast_expansion_sum_zeroelim(xylen, detxy, zlen, det384z, cdet);
3491
3492 temp48alen = fast_expansion_sum_zeroelim(abclen, abc, eaclen, eac, temp48a);
3493 temp48blen = fast_expansion_sum_zeroelim(bcelen, bce, eablen, eab, temp48b);
3494 for (i = 0; i < temp48blen; i++) {
3495 temp48b[i] = -temp48b[i];
3496 }
3497 eabclen = fast_expansion_sum_zeroelim(temp48alen, temp48a,
3498 temp48blen, temp48b, eabc);
3499 xlen = scale_expansion_zeroelim(eabclen, eabc, pd[0], temp192);
3500 xlen = scale_expansion_zeroelim(xlen, temp192, pd[0], det384x);
3501 ylen = scale_expansion_zeroelim(eabclen, eabc, pd[1], temp192);
3502 ylen = scale_expansion_zeroelim(ylen, temp192, pd[1], det384y);
3503 zlen = scale_expansion_zeroelim(eabclen, eabc, pd[2], temp192);
3504 zlen = scale_expansion_zeroelim(zlen, temp192, pd[2], det384z);
3505 xylen = fast_expansion_sum_zeroelim(xlen, det384x, ylen, det384y, detxy);
3506 dlen = fast_expansion_sum_zeroelim(xylen, detxy, zlen, det384z, ddet);
3507
3508 temp48alen = fast_expansion_sum_zeroelim(bcdlen, bcd, abdlen, abd, temp48a);
3509 temp48blen = fast_expansion_sum_zeroelim(cdalen, cda, abclen, abc, temp48b);
3510 for (i = 0; i < temp48blen; i++) {
3511 temp48b[i] = -temp48b[i];
3512 }
3513 abcdlen = fast_expansion_sum_zeroelim(temp48alen, temp48a,
3514 temp48blen, temp48b, abcd);
3515 xlen = scale_expansion_zeroelim(abcdlen, abcd, pe[0], temp192);
3516 xlen = scale_expansion_zeroelim(xlen, temp192, pe[0], det384x);
3517 ylen = scale_expansion_zeroelim(abcdlen, abcd, pe[1], temp192);
3518 ylen = scale_expansion_zeroelim(ylen, temp192, pe[1], det384y);
3519 zlen = scale_expansion_zeroelim(abcdlen, abcd, pe[2], temp192);
3520 zlen = scale_expansion_zeroelim(zlen, temp192, pe[2], det384z);
3521 xylen = fast_expansion_sum_zeroelim(xlen, det384x, ylen, det384y, detxy);
3522 elen = fast_expansion_sum_zeroelim(xylen, detxy, zlen, det384z, edet);
3523
3524 ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
3525 cdlen = fast_expansion_sum_zeroelim(clen, cdet, dlen, ddet, cddet);
3526 cdelen = fast_expansion_sum_zeroelim(cdlen, cddet, elen, edet, cdedet);
3527 deterlen = fast_expansion_sum_zeroelim(ablen, abdet, cdelen, cdedet, deter);
3528
3529 return deter[deterlen - 1];
3530 }
3531
3532 REAL insphereslow(REAL *pa, REAL *pb, REAL *pc, REAL *pd, REAL *pe)
3533 {
3534 INEXACT REAL aex, bex, cex, dex, aey, bey, cey, dey, aez, bez, cez, dez;
3535 REAL aextail, bextail, cextail, dextail;
3536 REAL aeytail, beytail, ceytail, deytail;
3537 REAL aeztail, beztail, ceztail, deztail;
3538 REAL negate, negatetail;
3539 INEXACT REAL axby7, bxcy7, cxdy7, dxay7, axcy7, bxdy7;
3540 INEXACT REAL bxay7, cxby7, dxcy7, axdy7, cxay7, dxby7;
3541 REAL axby[8], bxcy[8], cxdy[8], dxay[8], axcy[8], bxdy[8];
3542 REAL bxay[8], cxby[8], dxcy[8], axdy[8], cxay[8], dxby[8];
3543 REAL ab[16], bc[16], cd[16], da[16], ac[16], bd[16];
3544 int ablen, bclen, cdlen, dalen, aclen, bdlen;
3545 REAL temp32a[32], temp32b[32], temp64a[64], temp64b[64], temp64c[64];
3546 int temp32alen, temp32blen, temp64alen, temp64blen, temp64clen;
3547 REAL temp128[128], temp192[192];
3548 int temp128len, temp192len;
3549 REAL detx[384], detxx[768], detxt[384], detxxt[768], detxtxt[768];
3550 int xlen, xxlen, xtlen, xxtlen, xtxtlen;
3551 REAL x1[1536], x2[2304];
3552 int x1len, x2len;
3553 REAL dety[384], detyy[768], detyt[384], detyyt[768], detytyt[768];
3554 int ylen, yylen, ytlen, yytlen, ytytlen;
3555 REAL y1[1536], y2[2304];
3556 int y1len, y2len;
3557 REAL detz[384], detzz[768], detzt[384], detzzt[768], detztzt[768];
3558 int zlen, zzlen, ztlen, zztlen, ztztlen;
3559 REAL z1[1536], z2[2304];
3560 int z1len, z2len;
3561 REAL detxy[4608];
3562 int xylen;
3563 REAL adet[6912], bdet[6912], cdet[6912], ddet[6912];
3564 int alen, blen, clen, dlen;
3565 REAL abdet[13824], cddet[13824], deter[27648];
3566 int deterlen;
3567 int i;
3568
3569 INEXACT REAL bvirt;
3570 REAL avirt, bround, around;
3571 INEXACT REAL c;
3572 INEXACT REAL abig;
3573 REAL a0hi, a0lo, a1hi, a1lo, bhi, blo;
3574 REAL err1, err2, err3;
3575 INEXACT REAL _i, _j, _k, _l, _m, _n;
3576 REAL _0, _1, _2;
3577
3578 Two_Diff(pa[0], pe[0], aex, aextail);
3579 Two_Diff(pa[1], pe[1], aey, aeytail);
3580 Two_Diff(pa[2], pe[2], aez, aeztail);
3581 Two_Diff(pb[0], pe[0], bex, bextail);
3582 Two_Diff(pb[1], pe[1], bey, beytail);
3583 Two_Diff(pb[2], pe[2], bez, beztail);
3584 Two_Diff(pc[0], pe[0], cex, cextail);
3585 Two_Diff(pc[1], pe[1], cey, ceytail);
3586 Two_Diff(pc[2], pe[2], cez, ceztail);
3587 Two_Diff(pd[0], pe[0], dex, dextail);
3588 Two_Diff(pd[1], pe[1], dey, deytail);
3589 Two_Diff(pd[2], pe[2], dez, deztail);
3590
3591 Two_Two_Product(aex, aextail, bey, beytail,
3592 axby7, axby[6], axby[5], axby[4],
3593 axby[3], axby[2], axby[1], axby[0]);
3594 axby[7] = axby7;
3595 negate = -aey;
3596 negatetail = -aeytail;
3597 Two_Two_Product(bex, bextail, negate, negatetail,
3598 bxay7, bxay[6], bxay[5], bxay[4],
3599 bxay[3], bxay[2], bxay[1], bxay[0]);
3600 bxay[7] = bxay7;
3601 ablen = fast_expansion_sum_zeroelim(8, axby, 8, bxay, ab);
3602 Two_Two_Product(bex, bextail, cey, ceytail,
3603 bxcy7, bxcy[6], bxcy[5], bxcy[4],
3604 bxcy[3], bxcy[2], bxcy[1], bxcy[0]);
3605 bxcy[7] = bxcy7;
3606 negate = -bey;
3607 negatetail = -beytail;
3608 Two_Two_Product(cex, cextail, negate, negatetail,
3609 cxby7, cxby[6], cxby[5], cxby[4],
3610 cxby[3], cxby[2], cxby[1], cxby[0]);
3611 cxby[7] = cxby7;
3612 bclen = fast_expansion_sum_zeroelim(8, bxcy, 8, cxby, bc);
3613 Two_Two_Product(cex, cextail, dey, deytail,
3614 cxdy7, cxdy[6], cxdy[5], cxdy[4],
3615 cxdy[3], cxdy[2], cxdy[1], cxdy[0]);
3616 cxdy[7] = cxdy7;
3617 negate = -cey;
3618 negatetail = -ceytail;
3619 Two_Two_Product(dex, dextail, negate, negatetail,
3620 dxcy7, dxcy[6], dxcy[5], dxcy[4],
3621 dxcy[3], dxcy[2], dxcy[1], dxcy[0]);
3622 dxcy[7] = dxcy7;
3623 cdlen = fast_expansion_sum_zeroelim(8, cxdy, 8, dxcy, cd);
3624 Two_Two_Product(dex, dextail, aey, aeytail,
3625 dxay7, dxay[6], dxay[5], dxay[4],
3626 dxay[3], dxay[2], dxay[1], dxay[0]);
3627 dxay[7] = dxay7;
3628 negate = -dey;
3629 negatetail = -deytail;
3630 Two_Two_Product(aex, aextail, negate, negatetail,
3631 axdy7, axdy[6], axdy[5], axdy[4],
3632 axdy[3], axdy[2], axdy[1], axdy[0]);
3633 axdy[7] = axdy7;
3634 dalen = fast_expansion_sum_zeroelim(8, dxay, 8, axdy, da);
3635 Two_Two_Product(aex, aextail, cey, ceytail,
3636 axcy7, axcy[6], axcy[5], axcy[4],
3637 axcy[3], axcy[2], axcy[1], axcy[0]);
3638 axcy[7] = axcy7;
3639 negate = -aey;
3640 negatetail = -aeytail;
3641 Two_Two_Product(cex, cextail, negate, negatetail,
3642 cxay7, cxay[6], cxay[5], cxay[4],
3643 cxay[3], cxay[2], cxay[1], cxay[0]);
3644 cxay[7] = cxay7;
3645 aclen = fast_expansion_sum_zeroelim(8, axcy, 8, cxay, ac);
3646 Two_Two_Product(bex, bextail, dey, deytail,
3647 bxdy7, bxdy[6], bxdy[5], bxdy[4],
3648 bxdy[3], bxdy[2], bxdy[1], bxdy[0]);
3649 bxdy[7] = bxdy7;
3650 negate = -bey;
3651 negatetail = -beytail;
3652 Two_Two_Product(dex, dextail, negate, negatetail,
3653 dxby7, dxby[6], dxby[5], dxby[4],
3654 dxby[3], dxby[2], dxby[1], dxby[0]);
3655 dxby[7] = dxby7;
3656 bdlen = fast_expansion_sum_zeroelim(8, bxdy, 8, dxby, bd);
3657
3658 temp32alen = scale_expansion_zeroelim(cdlen, cd, -bez, temp32a);
3659 temp32blen = scale_expansion_zeroelim(cdlen, cd, -beztail, temp32b);
3660 temp64alen = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3661 temp32blen, temp32b, temp64a);
3662 temp32alen = scale_expansion_zeroelim(bdlen, bd, cez, temp32a);
3663 temp32blen = scale_expansion_zeroelim(bdlen, bd, ceztail, temp32b);
3664 temp64blen = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3665 temp32blen, temp32b, temp64b);
3666 temp32alen = scale_expansion_zeroelim(bclen, bc, -dez, temp32a);
3667 temp32blen = scale_expansion_zeroelim(bclen, bc, -deztail, temp32b);
3668 temp64clen = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3669 temp32blen, temp32b, temp64c);
3670 temp128len = fast_expansion_sum_zeroelim(temp64alen, temp64a,
3671 temp64blen, temp64b, temp128);
3672 temp192len = fast_expansion_sum_zeroelim(temp64clen, temp64c,
3673 temp128len, temp128, temp192);
3674 xlen = scale_expansion_zeroelim(temp192len, temp192, aex, detx);
3675 xxlen = scale_expansion_zeroelim(xlen, detx, aex, detxx);
3676 xtlen = scale_expansion_zeroelim(temp192len, temp192, aextail, detxt);
3677 xxtlen = scale_expansion_zeroelim(xtlen, detxt, aex, detxxt);
3678 for (i = 0; i < xxtlen; i++) {
3679 detxxt[i] *= 2.0;
3680 }
3681 xtxtlen = scale_expansion_zeroelim(xtlen, detxt, aextail, detxtxt);
3682 x1len = fast_expansion_sum_zeroelim(xxlen, detxx, xxtlen, detxxt, x1);
3683 x2len = fast_expansion_sum_zeroelim(x1len, x1, xtxtlen, detxtxt, x2);
3684 ylen = scale_expansion_zeroelim(temp192len, temp192, aey, dety);
3685 yylen = scale_expansion_zeroelim(ylen, dety, aey, detyy);
3686 ytlen = scale_expansion_zeroelim(temp192len, temp192, aeytail, detyt);
3687 yytlen = scale_expansion_zeroelim(ytlen, detyt, aey, detyyt);
3688 for (i = 0; i < yytlen; i++) {
3689 detyyt[i] *= 2.0;
3690 }
3691 ytytlen = scale_expansion_zeroelim(ytlen, detyt, aeytail, detytyt);
3692 y1len = fast_expansion_sum_zeroelim(yylen, detyy, yytlen, detyyt, y1);
3693 y2len = fast_expansion_sum_zeroelim(y1len, y1, ytytlen, detytyt, y2);
3694 zlen = scale_expansion_zeroelim(temp192len, temp192, aez, detz);
3695 zzlen = scale_expansion_zeroelim(zlen, detz, aez, detzz);
3696 ztlen = scale_expansion_zeroelim(temp192len, temp192, aeztail, detzt);
3697 zztlen = scale_expansion_zeroelim(ztlen, detzt, aez, detzzt);
3698 for (i = 0; i < zztlen; i++) {
3699 detzzt[i] *= 2.0;
3700 }
3701 ztztlen = scale_expansion_zeroelim(ztlen, detzt, aeztail, detztzt);
3702 z1len = fast_expansion_sum_zeroelim(zzlen, detzz, zztlen, detzzt, z1);
3703 z2len = fast_expansion_sum_zeroelim(z1len, z1, ztztlen, detztzt, z2);
3704 xylen = fast_expansion_sum_zeroelim(x2len, x2, y2len, y2, detxy);
3705 alen = fast_expansion_sum_zeroelim(z2len, z2, xylen, detxy, adet);
3706
3707 temp32alen = scale_expansion_zeroelim(dalen, da, cez, temp32a);
3708 temp32blen = scale_expansion_zeroelim(dalen, da, ceztail, temp32b);
3709 temp64alen = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3710 temp32blen, temp32b, temp64a);
3711 temp32alen = scale_expansion_zeroelim(aclen, ac, dez, temp32a);
3712 temp32blen = scale_expansion_zeroelim(aclen, ac, deztail, temp32b);
3713 temp64blen = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3714 temp32blen, temp32b, temp64b);
3715 temp32alen = scale_expansion_zeroelim(cdlen, cd, aez, temp32a);
3716 temp32blen = scale_expansion_zeroelim(cdlen, cd, aeztail, temp32b);
3717 temp64clen = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3718 temp32blen, temp32b, temp64c);
3719 temp128len = fast_expansion_sum_zeroelim(temp64alen, temp64a,
3720 temp64blen, temp64b, temp128);
3721 temp192len = fast_expansion_sum_zeroelim(temp64clen, temp64c,
3722 temp128len, temp128, temp192);
3723 xlen = scale_expansion_zeroelim(temp192len, temp192, bex, detx);
3724 xxlen = scale_expansion_zeroelim(xlen, detx, bex, detxx);
3725 xtlen = scale_expansion_zeroelim(temp192len, temp192, bextail, detxt);
3726 xxtlen = scale_expansion_zeroelim(xtlen, detxt, bex, detxxt);
3727 for (i = 0; i < xxtlen; i++) {
3728 detxxt[i] *= 2.0;
3729 }
3730 xtxtlen = scale_expansion_zeroelim(xtlen, detxt, bextail, detxtxt);
3731 x1len = fast_expansion_sum_zeroelim(xxlen, detxx, xxtlen, detxxt, x1);
3732 x2len = fast_expansion_sum_zeroelim(x1len, x1, xtxtlen, detxtxt, x2);
3733 ylen = scale_expansion_zeroelim(temp192len, temp192, bey, dety);
3734 yylen = scale_expansion_zeroelim(ylen, dety, bey, detyy);
3735 ytlen = scale_expansion_zeroelim(temp192len, temp192, beytail, detyt);
3736 yytlen = scale_expansion_zeroelim(ytlen, detyt, bey, detyyt);
3737 for (i = 0; i < yytlen; i++) {
3738 detyyt[i] *= 2.0;
3739 }
3740 ytytlen = scale_expansion_zeroelim(ytlen, detyt, beytail, detytyt);
3741 y1len = fast_expansion_sum_zeroelim(yylen, detyy, yytlen, detyyt, y1);
3742 y2len = fast_expansion_sum_zeroelim(y1len, y1, ytytlen, detytyt, y2);
3743 zlen = scale_expansion_zeroelim(temp192len, temp192, bez, detz);
3744 zzlen = scale_expansion_zeroelim(zlen, detz, bez, detzz);
3745 ztlen = scale_expansion_zeroelim(temp192len, temp192, beztail, detzt);
3746 zztlen = scale_expansion_zeroelim(ztlen, detzt, bez, detzzt);
3747 for (i = 0; i < zztlen; i++) {
3748 detzzt[i] *= 2.0;
3749 }
3750 ztztlen = scale_expansion_zeroelim(ztlen, detzt, beztail, detztzt);
3751 z1len = fast_expansion_sum_zeroelim(zzlen, detzz, zztlen, detzzt, z1);
3752 z2len = fast_expansion_sum_zeroelim(z1len, z1, ztztlen, detztzt, z2);
3753 xylen = fast_expansion_sum_zeroelim(x2len, x2, y2len, y2, detxy);
3754 blen = fast_expansion_sum_zeroelim(z2len, z2, xylen, detxy, bdet);
3755
3756 temp32alen = scale_expansion_zeroelim(ablen, ab, -dez, temp32a);
3757 temp32blen = scale_expansion_zeroelim(ablen, ab, -deztail, temp32b);
3758 temp64alen = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3759 temp32blen, temp32b, temp64a);
3760 temp32alen = scale_expansion_zeroelim(bdlen, bd, -aez, temp32a);
3761 temp32blen = scale_expansion_zeroelim(bdlen, bd, -aeztail, temp32b);
3762 temp64blen = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3763 temp32blen, temp32b, temp64b);
3764 temp32alen = scale_expansion_zeroelim(dalen, da, -bez, temp32a);
3765 temp32blen = scale_expansion_zeroelim(dalen, da, -beztail, temp32b);
3766 temp64clen = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3767 temp32blen, temp32b, temp64c);
3768 temp128len = fast_expansion_sum_zeroelim(temp64alen, temp64a,
3769 temp64blen, temp64b, temp128);
3770 temp192len = fast_expansion_sum_zeroelim(temp64clen, temp64c,
3771 temp128len, temp128, temp192);
3772 xlen = scale_expansion_zeroelim(temp192len, temp192, cex, detx);
3773 xxlen = scale_expansion_zeroelim(xlen, detx, cex, detxx);
3774 xtlen = scale_expansion_zeroelim(temp192len, temp192, cextail, detxt);
3775 xxtlen = scale_expansion_zeroelim(xtlen, detxt, cex, detxxt);
3776 for (i = 0; i < xxtlen; i++) {
3777 detxxt[i] *= 2.0;
3778 }
3779 xtxtlen = scale_expansion_zeroelim(xtlen, detxt, cextail, detxtxt);
3780 x1len = fast_expansion_sum_zeroelim(xxlen, detxx, xxtlen, detxxt, x1);
3781 x2len = fast_expansion_sum_zeroelim(x1len, x1, xtxtlen, detxtxt, x2);
3782 ylen = scale_expansion_zeroelim(temp192len, temp192, cey, dety);
3783 yylen = scale_expansion_zeroelim(ylen, dety, cey, detyy);
3784 ytlen = scale_expansion_zeroelim(temp192len, temp192, ceytail, detyt);
3785 yytlen = scale_expansion_zeroelim(ytlen, detyt, cey, detyyt);
3786 for (i = 0; i < yytlen; i++) {
3787 detyyt[i] *= 2.0;
3788 }
3789 ytytlen = scale_expansion_zeroelim(ytlen, detyt, ceytail, detytyt);
3790 y1len = fast_expansion_sum_zeroelim(yylen, detyy, yytlen, detyyt, y1);
3791 y2len = fast_expansion_sum_zeroelim(y1len, y1, ytytlen, detytyt, y2);
3792 zlen = scale_expansion_zeroelim(temp192len, temp192, cez, detz);
3793 zzlen = scale_expansion_zeroelim(zlen, detz, cez, detzz);
3794 ztlen = scale_expansion_zeroelim(temp192len, temp192, ceztail, detzt);
3795 zztlen = scale_expansion_zeroelim(ztlen, detzt, cez, detzzt);
3796 for (i = 0; i < zztlen; i++) {
3797 detzzt[i] *= 2.0;
3798 }
3799 ztztlen = scale_expansion_zeroelim(ztlen, detzt, ceztail, detztzt);
3800 z1len = fast_expansion_sum_zeroelim(zzlen, detzz, zztlen, detzzt, z1);
3801 z2len = fast_expansion_sum_zeroelim(z1len, z1, ztztlen, detztzt, z2);
3802 xylen = fast_expansion_sum_zeroelim(x2len, x2, y2len, y2, detxy);
3803 clen = fast_expansion_sum_zeroelim(z2len, z2, xylen, detxy, cdet);
3804
3805 temp32alen = scale_expansion_zeroelim(bclen, bc, aez, temp32a);
3806 temp32blen = scale_expansion_zeroelim(bclen, bc, aeztail, temp32b);
3807 temp64alen = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3808 temp32blen, temp32b, temp64a);
3809 temp32alen = scale_expansion_zeroelim(aclen, ac, -bez, temp32a);
3810 temp32blen = scale_expansion_zeroelim(aclen, ac, -beztail, temp32b);
3811 temp64blen = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3812 temp32blen, temp32b, temp64b);
3813 temp32alen = scale_expansion_zeroelim(ablen, ab, cez, temp32a);
3814 temp32blen = scale_expansion_zeroelim(ablen, ab, ceztail, temp32b);
3815 temp64clen = fast_expansion_sum_zeroelim(temp32alen, temp32a,
3816 temp32blen, temp32b, temp64c);
3817 temp128len = fast_expansion_sum_zeroelim(temp64alen, temp64a,
3818 temp64blen, temp64b, temp128);
3819 temp192len = fast_expansion_sum_zeroelim(temp64clen, temp64c,
3820 temp128len, temp128, temp192);
3821 xlen = scale_expansion_zeroelim(temp192len, temp192, dex, detx);
3822 xxlen = scale_expansion_zeroelim(xlen, detx, dex, detxx);
3823 xtlen = scale_expansion_zeroelim(temp192len, temp192, dextail, detxt);
3824 xxtlen = scale_expansion_zeroelim(xtlen, detxt, dex, detxxt);
3825 for (i = 0; i < xxtlen; i++) {
3826 detxxt[i] *= 2.0;
3827 }
3828 xtxtlen = scale_expansion_zeroelim(xtlen, detxt, dextail, detxtxt);
3829 x1len = fast_expansion_sum_zeroelim(xxlen, detxx, xxtlen, detxxt, x1);
3830 x2len = fast_expansion_sum_zeroelim(x1len, x1, xtxtlen, detxtxt, x2);
3831 ylen = scale_expansion_zeroelim(temp192len, temp192, dey, dety);
3832 yylen = scale_expansion_zeroelim(ylen, dety, dey, detyy);
3833 ytlen = scale_expansion_zeroelim(temp192len, temp192, deytail, detyt);
3834 yytlen = scale_expansion_zeroelim(ytlen, detyt, dey, detyyt);
3835 for (i = 0; i < yytlen; i++) {
3836 detyyt[i] *= 2.0;
3837 }
3838 ytytlen = scale_expansion_zeroelim(ytlen, detyt, deytail, detytyt);
3839 y1len = fast_expansion_sum_zeroelim(yylen, detyy, yytlen, detyyt, y1);
3840 y2len = fast_expansion_sum_zeroelim(y1len, y1, ytytlen, detytyt, y2);
3841 zlen = scale_expansion_zeroelim(temp192len, temp192, dez, detz);
3842 zzlen = scale_expansion_zeroelim(zlen, detz, dez, detzz);
3843 ztlen = scale_expansion_zeroelim(temp192len, temp192, deztail, detzt);
3844 zztlen = scale_expansion_zeroelim(ztlen, detzt, dez, detzzt);
3845 for (i = 0; i < zztlen; i++) {
3846 detzzt[i] *= 2.0;
3847 }
3848 ztztlen = scale_expansion_zeroelim(ztlen, detzt, deztail, detztzt);
3849 z1len = fast_expansion_sum_zeroelim(zzlen, detzz, zztlen, detzzt, z1);
3850 z2len = fast_expansion_sum_zeroelim(z1len, z1, ztztlen, detztzt, z2);
3851 xylen = fast_expansion_sum_zeroelim(x2len, x2, y2len, y2, detxy);
3852 dlen = fast_expansion_sum_zeroelim(z2len, z2, xylen, detxy, ddet);
3853
3854 ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
3855 cdlen = fast_expansion_sum_zeroelim(clen, cdet, dlen, ddet, cddet);
3856 deterlen = fast_expansion_sum_zeroelim(ablen, abdet, cdlen, cddet, deter);
3857
3858 return deter[deterlen - 1];
3859 }
3860
3861 REAL insphereadapt(REAL *pa, REAL *pb, REAL *pc, REAL *pd, REAL *pe,
3862 REAL permanent)
3863 {
3864 INEXACT REAL aex, bex, cex, dex, aey, bey, cey, dey, aez, bez, cez, dez;
3865 REAL det, errbound;
3866
3867 INEXACT REAL aexbey1, bexaey1, bexcey1, cexbey1;
3868 INEXACT REAL cexdey1, dexcey1, dexaey1, aexdey1;
3869 INEXACT REAL aexcey1, cexaey1, bexdey1, dexbey1;
3870 REAL aexbey0, bexaey0, bexcey0, cexbey0;
3871 REAL cexdey0, dexcey0, dexaey0, aexdey0;
3872 REAL aexcey0, cexaey0, bexdey0, dexbey0;
3873 REAL ab[4], bc[4], cd[4], da[4], ac[4], bd[4];
3874 INEXACT REAL ab3, bc3, cd3, da3, ac3, bd3;
3875 REAL abeps, bceps, cdeps, daeps, aceps, bdeps;
3876 REAL temp8a[8], temp8b[8], temp8c[8], temp16[16], temp24[24], temp48[48];
3877 int temp8alen, temp8blen, temp8clen, temp16len, temp24len, temp48len;
3878 REAL xdet[96], ydet[96], zdet[96], xydet[192];
3879 int xlen, ylen, zlen, xylen;
3880 REAL adet[288], bdet[288], cdet[288], ddet[288];
3881 int alen, blen, clen, dlen;
3882 REAL abdet[576], cddet[576];
3883 int ablen, cdlen;
3884 REAL fin1[1152];
3885 int finlength;
3886
3887 REAL aextail, bextail, cextail, dextail;
3888 REAL aeytail, beytail, ceytail, deytail;
3889 REAL aeztail, beztail, ceztail, deztail;
3890
3891 INEXACT REAL bvirt;
3892 REAL avirt, bround, around;
3893 INEXACT REAL c;
3894 INEXACT REAL abig;
3895 REAL ahi, alo, bhi, blo;
3896 REAL err1, err2, err3;
3897 INEXACT REAL _i, _j;
3898 REAL _0;
3899
3900 aex = (REAL) (pa[0] - pe[0]);
3901 bex = (REAL) (pb[0] - pe[0]);
3902 cex = (REAL) (pc[0] - pe[0]);
3903 dex = (REAL) (pd[0] - pe[0]);
3904 aey = (REAL) (pa[1] - pe[1]);
3905 bey = (REAL) (pb[1] - pe[1]);
3906 cey = (REAL) (pc[1] - pe[1]);
3907 dey = (REAL) (pd[1] - pe[1]);
3908 aez = (REAL) (pa[2] - pe[2]);
3909 bez = (REAL) (pb[2] - pe[2]);
3910 cez = (REAL) (pc[2] - pe[2]);
3911 dez = (REAL) (pd[2] - pe[2]);
3912
3913 Two_Product(aex, bey, aexbey1, aexbey0);
3914 Two_Product(bex, aey, bexaey1, bexaey0);
3915 Two_Two_Diff(aexbey1, aexbey0, bexaey1, bexaey0, ab3, ab[2], ab[1], ab[0]);
3916 ab[3] = ab3;
3917
3918 Two_Product(bex, cey, bexcey1, bexcey0);
3919 Two_Product(cex, bey, cexbey1, cexbey0);
3920 Two_Two_Diff(bexcey1, bexcey0, cexbey1, cexbey0, bc3, bc[2], bc[1], bc[0]);
3921 bc[3] = bc3;
3922
3923 Two_Product(cex, dey, cexdey1, cexdey0);
3924 Two_Product(dex, cey, dexcey1, dexcey0);
3925 Two_Two_Diff(cexdey1, cexdey0, dexcey1, dexcey0, cd3, cd[2], cd[1], cd[0]);
3926 cd[3] = cd3;
3927
3928 Two_Product(dex, aey, dexaey1, dexaey0);
3929 Two_Product(aex, dey, aexdey1, aexdey0);
3930 Two_Two_Diff(dexaey1, dexaey0, aexdey1, aexdey0, da3, da[2], da[1], da[0]);
3931 da[3] = da3;
3932
3933 Two_Product(aex, cey, aexcey1, aexcey0);
3934 Two_Product(cex, aey, cexaey1, cexaey0);
3935 Two_Two_Diff(aexcey1, aexcey0, cexaey1, cexaey0, ac3, ac[2], ac[1], ac[0]);
3936 ac[3] = ac3;
3937
3938 Two_Product(bex, dey, bexdey1, bexdey0);
3939 Two_Product(dex, bey, dexbey1, dexbey0);
3940 Two_Two_Diff(bexdey1, bexdey0, dexbey1, dexbey0, bd3, bd[2], bd[1], bd[0]);
3941 bd[3] = bd3;
3942
3943 temp8alen = scale_expansion_zeroelim(4, cd, bez, temp8a);
3944 temp8blen = scale_expansion_zeroelim(4, bd, -cez, temp8b);
3945 temp8clen = scale_expansion_zeroelim(4, bc, dez, temp8c);
3946 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a,
3947 temp8blen, temp8b, temp16);
3948 temp24len = fast_expansion_sum_zeroelim(temp8clen, temp8c,
3949 temp16len, temp16, temp24);
3950 temp48len = scale_expansion_zeroelim(temp24len, temp24, aex, temp48);
3951 xlen = scale_expansion_zeroelim(temp48len, temp48, -aex, xdet);
3952 temp48len = scale_expansion_zeroelim(temp24len, temp24, aey, temp48);
3953 ylen = scale_expansion_zeroelim(temp48len, temp48, -aey, ydet);
3954 temp48len = scale_expansion_zeroelim(temp24len, temp24, aez, temp48);
3955 zlen = scale_expansion_zeroelim(temp48len, temp48, -aez, zdet);
3956 xylen = fast_expansion_sum_zeroelim(xlen, xdet, ylen, ydet, xydet);
3957 alen = fast_expansion_sum_zeroelim(xylen, xydet, zlen, zdet, adet);
3958
3959 temp8alen = scale_expansion_zeroelim(4, da, cez, temp8a);
3960 temp8blen = scale_expansion_zeroelim(4, ac, dez, temp8b);
3961 temp8clen = scale_expansion_zeroelim(4, cd, aez, temp8c);
3962 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a,
3963 temp8blen, temp8b, temp16);
3964 temp24len = fast_expansion_sum_zeroelim(temp8clen, temp8c,
3965 temp16len, temp16, temp24);
3966 temp48len = scale_expansion_zeroelim(temp24len, temp24, bex, temp48);
3967 xlen = scale_expansion_zeroelim(temp48len, temp48, bex, xdet);
3968 temp48len = scale_expansion_zeroelim(temp24len, temp24, bey, temp48);
3969 ylen = scale_expansion_zeroelim(temp48len, temp48, bey, ydet);
3970 temp48len = scale_expansion_zeroelim(temp24len, temp24, bez, temp48);
3971 zlen = scale_expansion_zeroelim(temp48len, temp48, bez, zdet);
3972 xylen = fast_expansion_sum_zeroelim(xlen, xdet, ylen, ydet, xydet);
3973 blen = fast_expansion_sum_zeroelim(xylen, xydet, zlen, zdet, bdet);
3974
3975 temp8alen = scale_expansion_zeroelim(4, ab, dez, temp8a);
3976 temp8blen = scale_expansion_zeroelim(4, bd, aez, temp8b);
3977 temp8clen = scale_expansion_zeroelim(4, da, bez, temp8c);
3978 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a,
3979 temp8blen, temp8b, temp16);
3980 temp24len = fast_expansion_sum_zeroelim(temp8clen, temp8c,
3981 temp16len, temp16, temp24);
3982 temp48len = scale_expansion_zeroelim(temp24len, temp24, cex, temp48);
3983 xlen = scale_expansion_zeroelim(temp48len, temp48, -cex, xdet);
3984 temp48len = scale_expansion_zeroelim(temp24len, temp24, cey, temp48);
3985 ylen = scale_expansion_zeroelim(temp48len, temp48, -cey, ydet);
3986 temp48len = scale_expansion_zeroelim(temp24len, temp24, cez, temp48);
3987 zlen = scale_expansion_zeroelim(temp48len, temp48, -cez, zdet);
3988 xylen = fast_expansion_sum_zeroelim(xlen, xdet, ylen, ydet, xydet);
3989 clen = fast_expansion_sum_zeroelim(xylen, xydet, zlen, zdet, cdet);
3990
3991 temp8alen = scale_expansion_zeroelim(4, bc, aez, temp8a);
3992 temp8blen = scale_expansion_zeroelim(4, ac, -bez, temp8b);
3993 temp8clen = scale_expansion_zeroelim(4, ab, cez, temp8c);
3994 temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a,
3995 temp8blen, temp8b, temp16);
3996 temp24len = fast_expansion_sum_zeroelim(temp8clen, temp8c,
3997 temp16len, temp16, temp24);
3998 temp48len = scale_expansion_zeroelim(temp24len, temp24, dex, temp48);
3999 xlen = scale_expansion_zeroelim(temp48len, temp48, dex, xdet);
4000 temp48len = scale_expansion_zeroelim(temp24len, temp24, dey, temp48);
4001 ylen = scale_expansion_zeroelim(temp48len, temp48, dey, ydet);
4002 temp48len = scale_expansion_zeroelim(temp24len, temp24, dez, temp48);
4003 zlen = scale_expansion_zeroelim(temp48len, temp48, dez, zdet);
4004 xylen = fast_expansion_sum_zeroelim(xlen, xdet, ylen, ydet, xydet);
4005 dlen = fast_expansion_sum_zeroelim(xylen, xydet, zlen, zdet, ddet);
4006
4007 ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
4008 cdlen = fast_expansion_sum_zeroelim(clen, cdet, dlen, ddet, cddet);
4009 finlength = fast_expansion_sum_zeroelim(ablen, abdet, cdlen, cddet, fin1);
4010
4011 det = estimate(finlength, fin1);
4012 errbound = isperrboundB * permanent;
4013 if ((det >= errbound) || (-det >= errbound)) {
4014 return det;
4015 }
4016
4017 Two_Diff_Tail(pa[0], pe[0], aex, aextail);
4018 Two_Diff_Tail(pa[1], pe[1], aey, aeytail);
4019 Two_Diff_Tail(pa[2], pe[2], aez, aeztail);
4020 Two_Diff_Tail(pb[0], pe[0], bex, bextail);
4021 Two_Diff_Tail(pb[1], pe[1], bey, beytail);
4022 Two_Diff_Tail(pb[2], pe[2], bez, beztail);
4023 Two_Diff_Tail(pc[0], pe[0], cex, cextail);
4024 Two_Diff_Tail(pc[1], pe[1], cey, ceytail);
4025 Two_Diff_Tail(pc[2], pe[2], cez, ceztail);
4026 Two_Diff_Tail(pd[0], pe[0], dex, dextail);
4027 Two_Diff_Tail(pd[1], pe[1], dey, deytail);
4028 Two_Diff_Tail(pd[2], pe[2], dez, deztail);
4029 if ((aextail == 0.0) && (aeytail == 0.0) && (aeztail == 0.0)
4030 && (bextail == 0.0) && (beytail == 0.0) && (beztail == 0.0)
4031 && (cextail == 0.0) && (ceytail == 0.0) && (ceztail == 0.0)
4032 && (dextail == 0.0) && (deytail == 0.0) && (deztail == 0.0)) {
4033 return det;
4034 }
4035
4036 errbound = isperrboundC * permanent + resulterrbound * Absolute(det);
4037 abeps = (aex * beytail + bey * aextail)
4038 - (aey * bextail + bex * aeytail);
4039 bceps = (bex * ceytail + cey * bextail)
4040 - (bey * cextail + cex * beytail);
4041 cdeps = (cex * deytail + dey * cextail)
4042 - (cey * dextail + dex * ceytail);
4043 daeps = (dex * aeytail + aey * dextail)
4044 - (dey * aextail + aex * deytail);
4045 aceps = (aex * ceytail + cey * aextail)
4046 - (aey * cextail + cex * aeytail);
4047 bdeps = (bex * deytail + dey * bextail)
4048 - (bey * dextail + dex * beytail);
4049 det += (((bex * bex + bey * bey + bez * bez)
4050 * ((cez * daeps + dez * aceps + aez * cdeps)
4051 + (ceztail * da3 + deztail * ac3 + aeztail * cd3))
4052 + (dex * dex + dey * dey + dez * dez)
4053 * ((aez * bceps - bez * aceps + cez * abeps)
4054 + (aeztail * bc3 - beztail * ac3 + ceztail * ab3)))
4055 - ((aex * aex + aey * aey + aez * aez)
4056 * ((bez * cdeps - cez * bdeps + dez * bceps)
4057 + (beztail * cd3 - ceztail * bd3 + deztail * bc3))
4058 + (cex * cex + cey * cey + cez * cez)
4059 * ((dez * abeps + aez * bdeps + bez * daeps)
4060 + (deztail * ab3 + aeztail * bd3 + beztail * da3))))
4061 + 2.0 * (((bex * bextail + bey * beytail + bez * beztail)
4062 * (cez * da3 + dez * ac3 + aez * cd3)
4063 + (dex * dextail + dey * deytail + dez * deztail)
4064 * (aez * bc3 - bez * ac3 + cez * ab3))
4065 - ((aex * aextail + aey * aeytail + aez * aeztail)
4066 * (bez * cd3 - cez * bd3 + dez * bc3)
4067 + (cex * cextail + cey * ceytail + cez * ceztail)
4068 * (dez * ab3 + aez * bd3 + bez * da3)));
4069 if ((det >= errbound) || (-det >= errbound)) {
4070 return det;
4071 }
4072
4073 return insphereexact(pa, pb, pc, pd, pe);
4074 }
4075
4076 REAL insphere(REAL *pa, REAL *pb, REAL *pc, REAL *pd, REAL *pe)
4077 {
4078 REAL aex, bex, cex, dex;
4079 REAL aey, bey, cey, dey;
4080 REAL aez, bez, cez, dez;
4081 REAL aexbey, bexaey, bexcey, cexbey, cexdey, dexcey, dexaey, aexdey;
4082 REAL aexcey, cexaey, bexdey, dexbey;
4083 REAL alift, blift, clift, dlift;
4084 REAL ab, bc, cd, da, ac, bd;
4085 REAL abc, bcd, cda, dab;
4086 REAL aezplus, bezplus, cezplus, dezplus;
4087 REAL aexbeyplus, bexaeyplus, bexceyplus, cexbeyplus;
4088 REAL cexdeyplus, dexceyplus, dexaeyplus, aexdeyplus;
4089 REAL aexceyplus, cexaeyplus, bexdeyplus, dexbeyplus;
4090 REAL det;
4091 REAL permanent, errbound;
4092
4093 aex = pa[0] - pe[0];
4094 bex = pb[0] - pe[0];
4095 cex = pc[0] - pe[0];
4096 dex = pd[0] - pe[0];
4097 aey = pa[1] - pe[1];
4098 bey = pb[1] - pe[1];
4099 cey = pc[1] - pe[1];
4100 dey = pd[1] - pe[1];
4101 aez = pa[2] - pe[2];
4102 bez = pb[2] - pe[2];
4103 cez = pc[2] - pe[2];
4104 dez = pd[2] - pe[2];
4105
4106 aexbey = aex * bey;
4107 bexaey = bex * aey;
4108 ab = aexbey - bexaey;
4109 bexcey = bex * cey;
4110 cexbey = cex * bey;
4111 bc = bexcey - cexbey;
4112 cexdey = cex * dey;
4113 dexcey = dex * cey;
4114 cd = cexdey - dexcey;
4115 dexaey = dex * aey;
4116 aexdey = aex * dey;
4117 da = dexaey - aexdey;
4118
4119 aexcey = aex * cey;
4120 cexaey = cex * aey;
4121 ac = aexcey - cexaey;
4122 bexdey = bex * dey;
4123 dexbey = dex * bey;
4124 bd = bexdey - dexbey;
4125
4126 abc = aez * bc - bez * ac + cez * ab;
4127 bcd = bez * cd - cez * bd + dez * bc;
4128 cda = cez * da + dez * ac + aez * cd;
4129 dab = dez * ab + aez * bd + bez * da;
4130
4131 alift = aex * aex + aey * aey + aez * aez;
4132 blift = bex * bex + bey * bey + bez * bez;
4133 clift = cex * cex + cey * cey + cez * cez;
4134 dlift = dex * dex + dey * dey + dez * dez;
4135
4136 det = (dlift * abc - clift * dab) + (blift * cda - alift * bcd);
4137
4138 aezplus = Absolute(aez);
4139 bezplus = Absolute(bez);
4140 cezplus = Absolute(cez);
4141 dezplus = Absolute(dez);
4142 aexbeyplus = Absolute(aexbey);
4143 bexaeyplus = Absolute(bexaey);
4144 bexceyplus = Absolute(bexcey);
4145 cexbeyplus = Absolute(cexbey);
4146 cexdeyplus = Absolute(cexdey);
4147 dexceyplus = Absolute(dexcey);
4148 dexaeyplus = Absolute(dexaey);
4149 aexdeyplus = Absolute(aexdey);
4150 aexceyplus = Absolute(aexcey);
4151 cexaeyplus = Absolute(cexaey);
4152 bexdeyplus = Absolute(bexdey);
4153 dexbeyplus = Absolute(dexbey);
4154 permanent = ((cexdeyplus + dexceyplus) * bezplus
4155 + (dexbeyplus + bexdeyplus) * cezplus
4156 + (bexceyplus + cexbeyplus) * dezplus)
4157 * alift
4158 + ((dexaeyplus + aexdeyplus) * cezplus
4159 + (aexceyplus + cexaeyplus) * dezplus
4160 + (cexdeyplus + dexceyplus) * aezplus)
4161 * blift
4162 + ((aexbeyplus + bexaeyplus) * dezplus
4163 + (bexdeyplus + dexbeyplus) * aezplus
4164 + (dexaeyplus + aexdeyplus) * bezplus)
4165 * clift
4166 + ((bexceyplus + cexbeyplus) * aezplus
4167 + (cexaeyplus + aexceyplus) * bezplus
4168 + (aexbeyplus + bexaeyplus) * cezplus)
4169 * dlift;
4170 errbound = isperrboundA * permanent;
4171 if ((det > errbound) || (-det > errbound)) {
4172 return det;
4173 }
4174
4175 return insphereadapt(pa, pb, pc, pd, pe, permanent);
4176 }