predicates.cxx 188 KB

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