private static double Adapt(double[] pa, double[] pb, double[] pc, double[] pd, double[] pe, double permanent) { var aex = pa[0] - pe[0]; var bex = pb[0] - pe[0]; var cex = pc[0] - pe[0]; var dex = pd[0] - pe[0]; var aey = pa[1] - pe[1]; var bey = pb[1] - pe[1]; var cey = pc[1] - pe[1]; var dey = pd[1] - pe[1]; var aez = pa[2] - pe[2]; var bez = pb[2] - pe[2]; var cez = pc[2] - pe[2]; var dez = pd[2] - pe[2]; MacrosHelpers.TwoProduct(aex, bey, out double aexbey1, out double aexbey0); MacrosHelpers.TwoProduct(bex, aey, out double bexaey1, out double bexaey0); double[] ab = new double[4]; MacrosHelpers.TwoTwoDiff(aexbey1, aexbey0, bexaey1, bexaey0, out ab[3], out ab[2], out ab[1], out ab[0]); MacrosHelpers.TwoProduct(bex, cey, out double bexcey1, out double bexcey0); MacrosHelpers.TwoProduct(cex, bey, out double cexbey1, out double cexbey0); double[] bc = new double[4]; MacrosHelpers.TwoTwoDiff(bexcey1, bexcey0, cexbey1, cexbey0, out bc[3], out bc[2], out bc[1], out bc[0]); MacrosHelpers.TwoProduct(cex, dey, out double cexdey1, out double cexdey0); MacrosHelpers.TwoProduct(dex, cey, out double dexcey1, out double dexcey0); double[] cd = new double[4]; MacrosHelpers.TwoTwoDiff(cexdey1, cexdey0, dexcey1, dexcey0, out cd[3], out cd[2], out cd[1], out cd[0]); MacrosHelpers.TwoProduct(dex, aey, out double dexaey1, out double dexaey0); MacrosHelpers.TwoProduct(aex, dey, out double aexdey1, out double aexdey0); double[] da = new double[4]; MacrosHelpers.TwoTwoDiff(dexaey1, dexaey0, aexdey1, aexdey0, out da[3], out da[2], out da[1], out da[0]); MacrosHelpers.TwoProduct(aex, cey, out double aexcey1, out double aexcey0); MacrosHelpers.TwoProduct(cex, aey, out double cexaey1, out double cexaey0); double[] ac = new double[4]; MacrosHelpers.TwoTwoDiff(aexcey1, aexcey0, cexaey1, cexaey0, out ac[3], out ac[2], out ac[1], out ac[0]); MacrosHelpers.TwoProduct(bex, dey, out double bexdey1, out double bexdey0); MacrosHelpers.TwoProduct(dex, bey, out double dexbey1, out double dexbey0); double[] bd = new double[4]; MacrosHelpers.TwoTwoDiff(bexdey1, bexdey0, dexbey1, dexbey0, out bd[3], out bd[2], out bd[1], out bd[0]); double[] temp8a = new double[8]; double[] temp8b = new double[8]; double[] temp8c = new double[8]; var temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, cd, bez, temp8a); var temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bd, -cez, temp8b); var temp8clen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, dez, temp8c); double[] temp16 = new double[16]; var temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16); double[] temp24 = new double[24]; var temp24len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8clen, temp8c, temp16len, temp16, temp24); double[] temp48 = new double[48]; var temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, aex, temp48); double[] xdet = new double[96]; var xlen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, -aex, xdet); temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, aey, temp48); double[] ydet = new double[96]; var ylen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, -aey, ydet); temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, aez, temp48); double[] zdet = new double[96]; var zlen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, -aez, zdet); double[] xydet = new double[192]; var xylen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, xdet, ylen, ydet, xydet); double[] adet = new double[288]; var alen = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, xydet, zlen, zdet, adet); temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, da, cez, temp8a); temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ac, dez, temp8b); temp8clen = ArithmeticFunctions.ScaleExpansionZeroelim(4, cd, aez, temp8c); temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16); temp24len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8clen, temp8c, temp16len, temp16, temp24); temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, bex, temp48); xlen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, bex, xdet); temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, bey, temp48); ylen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, bey, ydet); temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, bez, temp48); zlen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, bez, zdet); xylen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, xdet, ylen, ydet, xydet); double[] bdet = new double[288]; var blen = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, xydet, zlen, zdet, bdet); temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, dez, temp8a); temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bd, aez, temp8b); temp8clen = ArithmeticFunctions.ScaleExpansionZeroelim(4, da, bez, temp8c); temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16); temp24len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8clen, temp8c, temp16len, temp16, temp24); temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, cex, temp48); xlen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, -cex, xdet); temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, cey, temp48); ylen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, -cey, ydet); temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, cez, temp48); zlen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, -cez, zdet); xylen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, xdet, ylen, ydet, xydet); double[] cdet = new double[288]; var clen = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, xydet, zlen, zdet, cdet); temp8alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, aez, temp8a); temp8blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ac, -bez, temp8b); temp8clen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cez, temp8c); temp16len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16); temp24len = ArithmeticFunctions.FastExpansionSumZeroelim(temp8clen, temp8c, temp16len, temp16, temp24); temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, dex, temp48); xlen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, dex, xdet); temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, dey, temp48); ylen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, dey, ydet); temp48len = ArithmeticFunctions.ScaleExpansionZeroelim(temp24len, temp24, dez, temp48); zlen = ArithmeticFunctions.ScaleExpansionZeroelim(temp48len, temp48, dez, zdet); xylen = ArithmeticFunctions.FastExpansionSumZeroelim(xlen, xdet, ylen, ydet, xydet); double[] ddet = new double[288]; var dlen = ArithmeticFunctions.FastExpansionSumZeroelim(xylen, xydet, zlen, zdet, ddet); double[] abdet = new double[576]; double[] cddet = new double[576]; double[] fin1 = new double[1152]; var ablen = ArithmeticFunctions.FastExpansionSumZeroelim(alen, adet, blen, bdet, abdet); var cdlen = ArithmeticFunctions.FastExpansionSumZeroelim(clen, cdet, dlen, ddet, cddet); var finlength = ArithmeticFunctions.FastExpansionSumZeroelim(ablen, abdet, cdlen, cddet, fin1); var det = ArithmeticFunctions.Estimate(finlength, fin1); var errbound = MacrosHelpers.IsperrboundB * permanent; if ((det >= errbound) || (-det >= errbound)) { return(det); } MacrosHelpers.TwoDiffTail(pa[0], pe[0], aex, out double aextail); MacrosHelpers.TwoDiffTail(pa[1], pe[1], aey, out double aeytail); MacrosHelpers.TwoDiffTail(pa[2], pe[2], aez, out double aeztail); MacrosHelpers.TwoDiffTail(pb[0], pe[0], bex, out double bextail); MacrosHelpers.TwoDiffTail(pb[1], pe[1], bey, out double beytail); MacrosHelpers.TwoDiffTail(pb[2], pe[2], bez, out double beztail); MacrosHelpers.TwoDiffTail(pc[0], pe[0], cex, out double cextail); MacrosHelpers.TwoDiffTail(pc[1], pe[1], cey, out double ceytail); MacrosHelpers.TwoDiffTail(pc[2], pe[2], cez, out double ceztail); MacrosHelpers.TwoDiffTail(pd[0], pe[0], dex, out double dextail); MacrosHelpers.TwoDiffTail(pd[1], pe[1], dey, out double deytail); MacrosHelpers.TwoDiffTail(pd[2], pe[2], dez, out double deztail); if ((aextail == 0.0) && (aeytail == 0.0) && (aeztail == 0.0) && (bextail == 0.0) && (beytail == 0.0) && (beztail == 0.0) && (cextail == 0.0) && (ceytail == 0.0) && (ceztail == 0.0) && (dextail == 0.0) && (deytail == 0.0) && (deztail == 0.0)) { return(det); } var da3 = da[3]; var ac3 = ac[3]; var cd3 = cd[3]; var ab3 = ab[3]; var bc3 = bc[3]; var bd3 = bd[3]; errbound = MacrosHelpers.IsperrboundC * permanent + MacrosHelpers.Resulterrbound * Math.Abs(det); var abeps = (aex * beytail + bey * aextail) - (aey * bextail + bex * aeytail); var bceps = (bex * ceytail + cey * bextail) - (bey * cextail + cex * beytail); var cdeps = (cex * deytail + dey * cextail) - (cey * dextail + dex * ceytail); var daeps = (dex * aeytail + aey * dextail) - (dey * aextail + aex * deytail); var aceps = (aex * ceytail + cey * aextail) - (aey * cextail + cex * aeytail); var bdeps = (bex * deytail + dey * bextail) - (bey * dextail + dex * beytail); det += (((bex * bex + bey * bey + bez * bez) * ((cez * daeps + dez * aceps + aez * cdeps) + (ceztail * da3 + deztail * ac3 + aeztail * cd3)) + (dex * dex + dey * dey + dez * dez) * ((aez * bceps - bez * aceps + cez * abeps) + (aeztail * bc3 - beztail * ac3 + ceztail * ab3))) - ((aex * aex + aey * aey + aez * aez) * ((bez * cdeps - cez * bdeps + dez * bceps) + (beztail * cd3 - ceztail * bd3 + deztail * bc3)) + (cex * cex + cey * cey + cez * cez) * ((dez * abeps + aez * bdeps + bez * daeps) + (deztail * ab3 + aeztail * bd3 + beztail * da3)))) + 2.0 * (((bex * bextail + bey * beytail + bez * beztail) * (cez * da3 + dez * ac3 + aez * cd3) + (dex * dextail + dey * deytail + dez * deztail) * (aez * bc3 - bez * ac3 + cez * ab3)) - ((aex * aextail + aey * aeytail + aez * aeztail) * (bez * cd3 - cez * bd3 + dez * bc3) + (cex * cextail + cey * ceytail + cez * ceztail) * (dez * ab3 + aez * bd3 + bez * da3))); if ((det >= errbound) || (-det >= errbound)) { return(det); } return(Exact(pa, pb, pc, pd, pe)); }
private static double Adapt(double[] pa, double[] pb, double[] pc, double[] pd, double permanent) { var adx = pa[0] - pd[0]; var bdx = pb[0] - pd[0]; var cdx = pc[0] - pd[0]; var ady = pa[1] - pd[1]; var bdy = pb[1] - pd[1]; var cdy = pc[1] - pd[1]; MacrosHelpers.TwoProduct(bdx, cdy, out double bdxcdy1, out double bdxcdy0); MacrosHelpers.TwoProduct(cdx, bdy, out double cdxbdy1, out double cdxbdy0); var bc = new double[4]; MacrosHelpers.TwoTwoDiff(bdxcdy1, bdxcdy0, cdxbdy1, cdxbdy0, out bc[3], out bc[2], out bc[1], out bc[0]); double[] axbc = new double[8]; var axbclen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, adx, axbc); double[] axxbc = new double[16]; var axxbclen = ArithmeticFunctions.ScaleExpansionZeroelim(axbclen, axbc, adx, axxbc); double[] aybc = new double[8]; var aybclen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, ady, aybc); double[] ayybc = new double[16]; var ayybclen = ArithmeticFunctions.ScaleExpansionZeroelim(aybclen, aybc, ady, ayybc); double[] adet = new double[32]; var alen = ArithmeticFunctions.FastExpansionSumZeroelim(axxbclen, axxbc, ayybclen, ayybc, adet); MacrosHelpers.TwoProduct(cdx, ady, out double cdxady1, out double cdxady0); MacrosHelpers.TwoProduct(adx, cdy, out double adxcdy1, out double adxcdy0); var ca = new double[4]; MacrosHelpers.TwoTwoDiff(cdxady1, cdxady0, adxcdy1, adxcdy0, out ca[3], out ca[2], out ca[1], out ca[0]); double[] bxca = new double[8]; var bxcalen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ca, bdx, bxca); double[] bxxca = new double[16]; var bxxcalen = ArithmeticFunctions.ScaleExpansionZeroelim(bxcalen, bxca, bdx, bxxca); double[] byca = new double[8]; var bycalen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ca, bdy, byca); double[] byyca = new double[16]; var byycalen = ArithmeticFunctions.ScaleExpansionZeroelim(bycalen, byca, bdy, byyca); double[] bdet = new double[32]; var blen = ArithmeticFunctions.FastExpansionSumZeroelim(bxxcalen, bxxca, byycalen, byyca, bdet); MacrosHelpers.TwoProduct(adx, bdy, out double adxbdy1, out double adxbdy0); MacrosHelpers.TwoProduct(bdx, ady, out double bdxady1, out double bdxady0); var ab = new double[4]; MacrosHelpers.TwoTwoDiff(adxbdy1, adxbdy0, bdxady1, bdxady0, out ab[3], out ab[2], out ab[1], out ab[0]); double[] cxab = new double[8]; var cxablen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cdx, cxab); double[] cxxab = new double[16]; var cxxablen = ArithmeticFunctions.ScaleExpansionZeroelim(cxablen, cxab, cdx, cxxab); double[] cyab = new double[8]; var cyablen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cdy, cyab); double[] cyyab = new double[16]; var cyyablen = ArithmeticFunctions.ScaleExpansionZeroelim(cyablen, cyab, cdy, cyyab); double[] cdet = new double[32]; var clen = ArithmeticFunctions.FastExpansionSumZeroelim(cxxablen, cxxab, cyyablen, cyyab, cdet); double[] abdet = new double[64]; var ablen = ArithmeticFunctions.FastExpansionSumZeroelim(alen, adet, blen, bdet, abdet); double[] fin1 = new double[1152]; var finlength = ArithmeticFunctions.FastExpansionSumZeroelim(ablen, abdet, clen, cdet, fin1); var det = ArithmeticFunctions.Estimate(finlength, fin1); var errbound = MacrosHelpers.IccerrboundB * permanent; if ((det >= errbound) || (-det >= errbound)) { return(det); } MacrosHelpers.TwoDiffTail(pa[0], pd[0], adx, out double adxtail); MacrosHelpers.TwoDiffTail(pa[1], pd[1], ady, out double adytail); MacrosHelpers.TwoDiffTail(pb[0], pd[0], bdx, out double bdxtail); MacrosHelpers.TwoDiffTail(pb[1], pd[1], bdy, out double bdytail); MacrosHelpers.TwoDiffTail(pc[0], pd[0], cdx, out double cdxtail); MacrosHelpers.TwoDiffTail(pc[1], pd[1], cdy, out double cdytail); if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0) && (adytail == 0.0) && (bdytail == 0.0) && (cdytail == 0.0)) { return(det); } errbound = MacrosHelpers.IccerrboundC * permanent + MacrosHelpers.Resulterrbound * Math.Abs(det); det += ((adx * adx + ady * ady) * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) + 2.0 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx)) + ((bdx * bdx + bdy * bdy) * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) + 2.0 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx)) + ((cdx * cdx + cdy * cdy) * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) + 2.0 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx)); if ((det >= errbound) || (-det >= errbound)) { return(det); } var finnow = fin1; var fin2 = new double[1152]; var finother = fin2; double[] aa = new double[4]; double[] bb = new double[4]; double[] cc = new double[4]; if ((bdxtail != 0.0) || (bdytail != 0.0) || (cdxtail != 0.0) || (cdytail != 0.0)) { MacrosHelpers.Square(adx, out double adxadx1, out double adxadx0); MacrosHelpers.Square(ady, out double adyady1, out double adyady0); MacrosHelpers.TwoTwoSum(adxadx1, adxadx0, adyady1, adyady0, out aa[3], out aa[2], out aa[1], out aa[0]); } if ((cdxtail != 0.0) || (cdytail != 0.0) || (adxtail != 0.0) || (adytail != 0.0)) { MacrosHelpers.Square(bdx, out double bdxbdx1, out double bdxbdx0); MacrosHelpers.Square(bdy, out double bdybdy1, out double bdybdy0); MacrosHelpers.TwoTwoSum(bdxbdx1, bdxbdx0, bdybdy1, bdybdy0, out bb[3], out bb[2], out bb[1], out bb[0]); } if ((adxtail != 0.0) || (adytail != 0.0) || (bdxtail != 0.0) || (bdytail != 0.0)) { MacrosHelpers.Square(cdx, out double cdxcdx1, out double cdxcdx0); MacrosHelpers.Square(cdy, out double cdycdy1, out double cdycdy0); MacrosHelpers.TwoTwoSum(cdxcdx1, cdxcdx0, cdycdy1, cdycdy0, out cc[3], out cc[2], out cc[1], out cc[0]); } double[] finswap; double[] temp16a = new double[16]; double[] temp32a = new double[32]; double[] temp16b = new double[16]; double[] temp32b = new double[32]; double[] temp16c = new double[16]; double[] temp48 = new double[48]; double[] axtbc = new double[8]; int axtbclen = 0; if (adxtail != 0.0) { axtbclen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, adxtail, axtbc); var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbclen, axtbc, 2.0 * adx, temp16a); double[] axtcc = new double[8]; var axtcclen = ArithmeticFunctions.ScaleExpansionZeroelim(4, cc, adxtail, axtcc); var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(axtcclen, axtcc, bdy, temp16b); double[] axtbb = new double[8]; var axtbblen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bb, adxtail, axtbb); var temp16clen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbblen, axtbb, -cdy, temp16c); var temp32alen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; } int aytbclen = 0; double[] aytbc = new double[8]; if (adytail != 0.0) { aytbclen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, adytail, aytbc); var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbclen, aytbc, 2.0 * ady, temp16a); double[] aytbb = new double[8]; var aytbblen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bb, adytail, aytbb); var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbblen, aytbb, cdx, temp16b); double[] aytcc = new double[8]; var aytcclen = ArithmeticFunctions.ScaleExpansionZeroelim(4, cc, adytail, aytcc); var temp16clen = ArithmeticFunctions.ScaleExpansionZeroelim(aytcclen, aytcc, -bdx, temp16c); var temp32alen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; } int bxtcalen = 0; double[] bxtca = new double[8]; if (bdxtail != 0.0) { bxtcalen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ca, bdxtail, bxtca); var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcalen, bxtca, 2.0 * bdx, temp16a); double[] bxtaa = new double[8]; var bxtaalen = ArithmeticFunctions.ScaleExpansionZeroelim(4, aa, bdxtail, bxtaa); var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtaalen, bxtaa, cdy, temp16b); double[] bxtcc = new double[8]; var bxtcclen = ArithmeticFunctions.ScaleExpansionZeroelim(4, cc, bdxtail, bxtcc); var temp16clen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcclen, bxtcc, -ady, temp16c); var temp32alen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; } int bytcalen = 0; double[] bytca = new double[8]; if (bdytail != 0.0) { bytcalen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ca, bdytail, bytca); var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcalen, bytca, 2.0 * bdy, temp16a); double[] bytcc = new double[8]; var bytcclen = ArithmeticFunctions.ScaleExpansionZeroelim(4, cc, bdytail, bytcc); var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcclen, bytcc, adx, temp16b); double[] bytaa = new double[8]; var bytaalen = ArithmeticFunctions.ScaleExpansionZeroelim(4, aa, bdytail, bytaa); var temp16clen = ArithmeticFunctions.ScaleExpansionZeroelim(bytaalen, bytaa, -cdx, temp16c); var temp32alen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; } int cxtablen = 0; double[] cxtab = new double[8]; if (cdxtail != 0.0) { cxtablen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cdxtail, cxtab); var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtablen, cxtab, 2.0 * cdx, temp16a); double[] cxtbb = new double[8]; var cxtbblen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bb, cdxtail, cxtbb); var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtbblen, cxtbb, ady, temp16b); double[] cxtaa = new double[8]; var cxtaalen = ArithmeticFunctions.ScaleExpansionZeroelim(4, aa, cdxtail, cxtaa); var temp16clen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtaalen, cxtaa, -bdy, temp16c); var temp32alen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; } int cytablen = 0; double[] cytab = new double[8]; if (cdytail != 0.0) { cytablen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cdytail, cytab); var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(cytablen, cytab, 2.0 * cdy, temp16a); double[] cytaa = new double[8]; var cytaalen = ArithmeticFunctions.ScaleExpansionZeroelim(4, aa, cdytail, cytaa); var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(cytaalen, cytaa, bdx, temp16b); double[] cytbb = new double[8]; var cytbblen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bb, cdytail, cytbb); var temp16clen = ArithmeticFunctions.ScaleExpansionZeroelim(cytbblen, cytbb, -adx, temp16c); var temp32alen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; } int bcttlen; double[] bct = new double[8]; int bctlen; var bctt = new double[4]; double[] temp64 = new double[64]; double[] u = new double[5]; double[] v = new double[5]; if ((adxtail != 0.0) || (adytail != 0.0)) { if ((bdxtail != 0.0) || (bdytail != 0.0) || (cdxtail != 0.0) || (cdytail != 0.0)) { MacrosHelpers.TwoProduct(bdxtail, cdy, out double ti1, out double ti0); MacrosHelpers.TwoProduct(bdx, cdytail, out double tj1, out double tj0); MacrosHelpers.TwoTwoSum(ti1, ti0, tj1, tj0, out u[3], out u[2], out u[1], out u[0]); var negate = -bdy; MacrosHelpers.TwoProduct(cdxtail, negate, out ti1, out ti0); negate = -bdytail; MacrosHelpers.TwoProduct(cdx, negate, out tj1, out tj0); MacrosHelpers.TwoTwoSum(ti1, ti0, tj1, tj0, out v[3], out v[2], out v[1], out v[0]); bctlen = ArithmeticFunctions.FastExpansionSumZeroelim(4, u, 4, v, bct); MacrosHelpers.TwoProduct(bdxtail, cdytail, out ti1, out ti0); MacrosHelpers.TwoProduct(cdxtail, bdytail, out tj1, out tj0); MacrosHelpers.TwoTwoDiff(ti1, ti0, tj1, tj0, out bctt[3], out bctt[2], out bctt[1], out bctt[0]); bcttlen = 4; } else { bct[0] = 0.0; bctlen = 1; bctt[0] = 0.0; bcttlen = 1; } double[] temp8 = new double[8]; if (adxtail != 0.0) { var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbclen, axtbc, adxtail, temp16a); double[] axtbct = new double[16]; var axtbctlen = ArithmeticFunctions.ScaleExpansionZeroelim(bctlen, bct, adxtail, axtbct); var temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbctlen, axtbct, 2.0 * adx, temp32a); var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; if (bdytail != 0.0) { var temp8len = ArithmeticFunctions.ScaleExpansionZeroelim(4, cc, adxtail, temp8); temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(temp8len, temp8, bdytail, temp16a); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp16alen, temp16a, finother); finswap = finnow; finnow = finother; finother = finswap; } if (cdytail != 0.0) { var temp8len = ArithmeticFunctions.ScaleExpansionZeroelim(4, bb, -adxtail, temp8); temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(temp8len, temp8, cdytail, temp16a); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp16alen, temp16a, finother); finswap = finnow; finnow = finother; finother = finswap; } temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbctlen, axtbct, adxtail, temp32a); double[] axtbctt = new double[8]; var axtbcttlen = ArithmeticFunctions.ScaleExpansionZeroelim(bcttlen, bctt, adxtail, axtbctt); temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbcttlen, axtbctt, 2.0 * adx, temp16a); var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(axtbcttlen, axtbctt, adxtail, temp16b); var temp32blen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); var temp64len = ArithmeticFunctions.FastExpansionSumZeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp64len, temp64, finother); finswap = finnow; finnow = finother; finother = finswap; } if (adytail != 0.0) { double[] aytbct = new double[16]; var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbclen, aytbc, adytail, temp16a); var aytbctlen = ArithmeticFunctions.ScaleExpansionZeroelim(bctlen, bct, adytail, aytbct); var temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbctlen, aytbct, 2.0 * ady, temp32a); var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbctlen, aytbct, adytail, temp32a); double[] aytbctt = new double[16]; var aytbcttlen = ArithmeticFunctions.ScaleExpansionZeroelim(bcttlen, bctt, adytail, aytbctt); temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbcttlen, aytbctt, 2.0 * ady, temp16a); var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(aytbcttlen, aytbctt, adytail, temp16b); var temp32blen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); var temp64len = ArithmeticFunctions.FastExpansionSumZeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp64len, temp64, finother); finswap = finnow; finnow = finother; finother = finswap; } } double[] cat = new double[8]; double[] catt = new double[4]; if ((bdxtail != 0.0) || (bdytail != 0.0)) { int cattlen; int catlen; if ((cdxtail != 0.0) || (cdytail != 0.0) || (adxtail != 0.0) || (adytail != 0.0)) { MacrosHelpers.TwoProduct(cdxtail, ady, out double ti1, out double ti0); MacrosHelpers.TwoProduct(cdx, adytail, out double tj1, out double tj0); MacrosHelpers.TwoTwoSum(ti1, ti0, tj1, tj0, out u[3], out u[2], out u[1], out u[0]); var negate = -cdy; MacrosHelpers.TwoProduct(adxtail, negate, out ti1, out ti0); negate = -cdytail; MacrosHelpers.TwoProduct(adx, negate, out tj1, out tj0); MacrosHelpers.TwoTwoSum(ti1, ti0, tj1, tj0, out v[3], out v[2], out v[1], out v[0]); catlen = ArithmeticFunctions.FastExpansionSumZeroelim(4, u, 4, v, cat); MacrosHelpers.TwoProduct(cdxtail, adytail, out ti1, out ti0); MacrosHelpers.TwoProduct(adxtail, cdytail, out tj1, out tj0); MacrosHelpers.TwoTwoDiff(ti1, ti0, tj1, tj0, out catt[3], out catt[2], out catt[1], out catt[0]); cattlen = 4; } else { cat[0] = 0.0; catlen = 1; catt[0] = 0.0; cattlen = 1; } double[] temp8 = new double[8]; double[] bxtcat = new double[16]; double[] bxtcatt = new double[8]; if (bdxtail != 0.0) { var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcalen, bxtca, bdxtail, temp16a); var bxtcatlen = ArithmeticFunctions.ScaleExpansionZeroelim(catlen, cat, bdxtail, bxtcat); var temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcatlen, bxtcat, 2.0 * bdx, temp32a); var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; if (cdytail != 0.0) { var temp8len = ArithmeticFunctions.ScaleExpansionZeroelim(4, aa, bdxtail, temp8); temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(temp8len, temp8, cdytail, temp16a); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp16alen, temp16a, finother); finswap = finnow; finnow = finother; finother = finswap; } if (adytail != 0.0) { var temp8len = ArithmeticFunctions.ScaleExpansionZeroelim(4, cc, -bdxtail, temp8); temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(temp8len, temp8, adytail, temp16a); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp16alen, temp16a, finother); finswap = finnow; finnow = finother; finother = finswap; } temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcatlen, bxtcat, bdxtail, temp32a); var bxtcattlen = ArithmeticFunctions.ScaleExpansionZeroelim(cattlen, catt, bdxtail, bxtcatt); temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcattlen, bxtcatt, 2.0 * bdx, temp16a); var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(bxtcattlen, bxtcatt, bdxtail, temp16b); var temp32blen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); var temp64len = ArithmeticFunctions.FastExpansionSumZeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp64len, temp64, finother); finswap = finnow; finnow = finother; finother = finswap; } double[] bytcat = new double[16]; double[] bytcatt = new double[8]; if (bdytail != 0.0) { var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcalen, bytca, bdytail, temp16a); var bytcatlen = ArithmeticFunctions.ScaleExpansionZeroelim(catlen, cat, bdytail, bytcat); var temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcatlen, bytcat, 2.0 * bdy, temp32a); var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcatlen, bytcat, bdytail, temp32a); var bytcattlen = ArithmeticFunctions.ScaleExpansionZeroelim(cattlen, catt, bdytail, bytcatt); temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcattlen, bytcatt, 2.0 * bdy, temp16a); var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(bytcattlen, bytcatt, bdytail, temp16b); var temp32blen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); var temp64len = ArithmeticFunctions.FastExpansionSumZeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp64len, temp64, finother); finswap = finnow; finnow = finother; finother = finswap; } } double[] abt = new double[8]; double[] abtt = new double[4]; if ((cdxtail != 0.0) || (cdytail != 0.0)) { int abtlen; int abttlen; if ((adxtail != 0.0) || (adytail != 0.0) || (bdxtail != 0.0) || (bdytail != 0.0)) { MacrosHelpers.TwoProduct(adxtail, bdy, out double ti1, out double ti0); MacrosHelpers.TwoProduct(adx, bdytail, out double tj1, out double tj0); MacrosHelpers.TwoTwoSum(ti1, ti0, tj1, tj0, out u[3], out u[2], out u[1], out u[0]); var negate = -ady; MacrosHelpers.TwoProduct(bdxtail, negate, out ti1, out ti0); negate = -adytail; MacrosHelpers.TwoProduct(bdx, negate, out tj1, out tj0); MacrosHelpers.TwoTwoSum(ti1, ti0, tj1, tj0, out v[3], out v[2], out v[1], out v[0]); abtlen = ArithmeticFunctions.FastExpansionSumZeroelim(4, u, 4, v, abt); MacrosHelpers.TwoProduct(adxtail, bdytail, out ti1, out ti0); MacrosHelpers.TwoProduct(bdxtail, adytail, out tj1, out tj0); MacrosHelpers.TwoTwoDiff(ti1, ti0, tj1, tj0, out abtt[3], out abtt[2], out abtt[1], out abtt[0]); abttlen = 4; } else { abt[0] = 0.0; abtlen = 1; abtt[0] = 0.0; abttlen = 1; } double[] temp8 = new double[8]; double[] cxtabt = new double[16]; double[] cxtabtt = new double[8]; if (cdxtail != 0.0) { var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtablen, cxtab, cdxtail, temp16a); var cxtabtlen = ArithmeticFunctions.ScaleExpansionZeroelim(abtlen, abt, cdxtail, cxtabt); var temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtabtlen, cxtabt, 2.0 * cdx, temp32a); var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; if (adytail != 0.0) { var temp8len = ArithmeticFunctions.ScaleExpansionZeroelim(4, bb, cdxtail, temp8); temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(temp8len, temp8, adytail, temp16a); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp16alen, temp16a, finother); finswap = finnow; finnow = finother; finother = finswap; } if (bdytail != 0.0) { var temp8len = ArithmeticFunctions.ScaleExpansionZeroelim(4, aa, -cdxtail, temp8); temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(temp8len, temp8, bdytail, temp16a); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp16alen, temp16a, finother); finswap = finnow; finnow = finother; finother = finswap; } temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtabtlen, cxtabt, cdxtail, temp32a); var cxtabttlen = ArithmeticFunctions.ScaleExpansionZeroelim(abttlen, abtt, cdxtail, cxtabtt); temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtabttlen, cxtabtt, 2.0 * cdx, temp16a); var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(cxtabttlen, cxtabtt, cdxtail, temp16b); var temp32blen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); var temp64len = ArithmeticFunctions.FastExpansionSumZeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp64len, temp64, finother); finswap = finnow; finnow = finother; finother = finswap; } double[] cytabt = new double[16]; double[] cytabtt = new double[8]; if (cdytail != 0.0) { var temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(cytablen, cytab, cdytail, temp16a); var cytabtlen = ArithmeticFunctions.ScaleExpansionZeroelim(abtlen, abt, cdytail, cytabt); var temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(cytabtlen, cytabt, 2.0 * cdy, temp32a); var temp48len = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; temp32alen = ArithmeticFunctions.ScaleExpansionZeroelim(cytabtlen, cytabt, cdytail, temp32a); var cytabttlen = ArithmeticFunctions.ScaleExpansionZeroelim(abttlen, abtt, cdytail, cytabtt); temp16alen = ArithmeticFunctions.ScaleExpansionZeroelim(cytabttlen, cytabtt, 2.0 * cdy, temp16a); var temp16blen = ArithmeticFunctions.ScaleExpansionZeroelim(cytabttlen, cytabtt, cdytail, temp16b); var temp32blen = ArithmeticFunctions.FastExpansionSumZeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); var temp64len = ArithmeticFunctions.FastExpansionSumZeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, temp64len, temp64, finother); finswap = finnow; finnow = finother; finother = finswap; } } return(finnow[finlength - 1]); }
private static double Adapt(double[] pa, double[] pb, double[] pc, double[] pd, double permanent) { var adx = pa[0] - pd[0]; var bdx = pb[0] - pd[0]; var cdx = pc[0] - pd[0]; var ady = pa[1] - pd[1]; var bdy = pb[1] - pd[1]; var cdy = pc[1] - pd[1]; var adz = pa[2] - pd[2]; var bdz = pb[2] - pd[2]; var cdz = pc[2] - pd[2]; MacrosHelpers.TwoProduct(bdx, cdy, out double bdxcdy1, out double bdxcdy0); MacrosHelpers.TwoProduct(cdx, bdy, out double cdxbdy1, out double cdxbdy0); var bc = new double[4]; MacrosHelpers.TwoTwoDiff(bdxcdy1, bdxcdy0, cdxbdy1, cdxbdy0, out bc[3], out bc[2], out bc[1], out bc[0]); double[] adet = new double[8]; var alen = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, adz, adet); MacrosHelpers.TwoProduct(cdx, ady, out double cdxady1, out double cdxady0); MacrosHelpers.TwoProduct(adx, cdy, out double adxcdy1, out double adxcdy0); var ca = new double[4]; MacrosHelpers.TwoTwoDiff(cdxady1, cdxady0, adxcdy1, adxcdy0, out ca[3], out ca[2], out ca[1], out ca[0]); double[] bdet = new double[8]; var blen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ca, bdz, bdet); MacrosHelpers.TwoProduct(adx, bdy, out double adxbdy1, out double adxbdy0); MacrosHelpers.TwoProduct(bdx, ady, out double bdxady1, out double bdxady0); var ab = new double[4]; MacrosHelpers.TwoTwoDiff(adxbdy1, adxbdy0, bdxady1, bdxady0, out ab[3], out ab[2], out ab[1], out ab[0]); double[] cdet = new double[8]; var clen = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cdz, cdet); double[] abdet = new double[16]; var ablen = ArithmeticFunctions.FastExpansionSumZeroelim(alen, adet, blen, bdet, abdet); double[] fin1 = new double[192]; var finlength = ArithmeticFunctions.FastExpansionSumZeroelim(ablen, abdet, clen, cdet, fin1); var det = ArithmeticFunctions.Estimate(finlength, fin1); var errbound = MacrosHelpers.O3derrboundB * permanent; if ((det >= errbound) || (-det >= errbound)) { return(det); } MacrosHelpers.TwoDiffTail(pa[0], pd[0], adx, out double adxtail); MacrosHelpers.TwoDiffTail(pb[0], pd[0], bdx, out double bdxtail); MacrosHelpers.TwoDiffTail(pc[0], pd[0], cdx, out double cdxtail); MacrosHelpers.TwoDiffTail(pa[1], pd[1], ady, out double adytail); MacrosHelpers.TwoDiffTail(pb[1], pd[1], bdy, out double bdytail); MacrosHelpers.TwoDiffTail(pc[1], pd[1], cdy, out double cdytail); MacrosHelpers.TwoDiffTail(pa[2], pd[2], adz, out double adztail); MacrosHelpers.TwoDiffTail(pb[2], pd[2], bdz, out double bdztail); MacrosHelpers.TwoDiffTail(pc[2], pd[2], cdz, out double cdztail); if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0) && (adytail == 0.0) && (bdytail == 0.0) && (cdytail == 0.0) && (adztail == 0.0) && (bdztail == 0.0) && (cdztail == 0.0)) { return(det); } errbound = MacrosHelpers.O3derrboundC * permanent + MacrosHelpers.Resulterrbound * Math.Abs(det); det += (adz * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) + adztail * (bdx * cdy - bdy * cdx)) + (bdz * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) + bdztail * (cdx * ady - cdy * adx)) + (cdz * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) + cdztail * (adx * bdy - ady * bdx)); if ((det >= errbound) || (-det >= errbound)) { return(det); } var finnow = fin1; var fin2 = new double[192]; var finother = fin2; double[] at_b = new double[4]; double[] at_c = new double[4]; int at_blen; int at_clen; if (adxtail == 0.0) { if (adytail == 0.0) { at_b[0] = 0.0; at_blen = 1; at_c[0] = 0.0; at_clen = 1; } else { var negate = -adytail; MacrosHelpers.TwoProduct(negate, bdx, out at_b[1], out at_b[0]); at_blen = 2; MacrosHelpers.TwoProduct(adytail, cdx, out at_c[1], out at_c[0]); at_clen = 2; } } else { if (adytail == 0.0) { MacrosHelpers.TwoProduct(adxtail, bdy, out at_b[1], out at_b[0]); at_blen = 2; var negate = -adxtail; MacrosHelpers.TwoProduct(negate, cdy, out at_c[1], out at_c[0]); at_clen = 2; } else { MacrosHelpers.TwoProduct(adxtail, bdy, out double adxt_bdy1, out double adxt_bdy0); MacrosHelpers.TwoProduct(adytail, bdx, out double adyt_bdx1, out double adyt_bdx0); MacrosHelpers.TwoTwoDiff(adxt_bdy1, adxt_bdy0, adyt_bdx1, adyt_bdx0, out double at_blarge, out at_b[2], out at_b[1], out at_b[0]); at_b[3] = at_blarge; at_blen = 4; MacrosHelpers.TwoProduct(adytail, cdx, out double adyt_cdx1, out double adyt_cdx0); MacrosHelpers.TwoProduct(adxtail, cdy, out double adxt_cdy1, out double adxt_cdy0); MacrosHelpers.TwoTwoDiff(adyt_cdx1, adyt_cdx0, adxt_cdy1, adxt_cdy0, out at_c[3], out at_c[2], out at_c[1], out at_c[0]); at_clen = 4; } } double[] bt_c = new double[4]; double[] bt_a = new double[4]; int bt_alen; int bt_clen; if (bdxtail == 0.0) { if (bdytail == 0.0) { bt_c[0] = 0.0; bt_clen = 1; bt_a[0] = 0.0; bt_alen = 1; } else { var negate = -bdytail; MacrosHelpers.TwoProduct(negate, cdx, out bt_c[1], out bt_c[0]); bt_clen = 2; MacrosHelpers.TwoProduct(bdytail, adx, out bt_a[1], out bt_a[0]); bt_alen = 2; } } else { if (bdytail == 0.0) { MacrosHelpers.TwoProduct(bdxtail, cdy, out bt_c[1], out bt_c[0]); bt_clen = 2; var negate = -bdxtail; MacrosHelpers.TwoProduct(negate, ady, out bt_a[1], out bt_a[0]); bt_alen = 2; } else { MacrosHelpers.TwoProduct(bdxtail, cdy, out double bdxt_cdy1, out double bdxt_cdy0); MacrosHelpers.TwoProduct(bdytail, cdx, out double bdyt_cdx1, out double bdyt_cdx0); MacrosHelpers.TwoTwoDiff(bdxt_cdy1, bdxt_cdy0, bdyt_cdx1, bdyt_cdx0, out bt_c[3], out bt_c[2], out bt_c[1], out bt_c[0]); bt_clen = 4; MacrosHelpers.TwoProduct(bdytail, adx, out double bdyt_adx1, out double bdyt_adx0); MacrosHelpers.TwoProduct(bdxtail, ady, out double bdxt_ady1, out double bdxt_ady0); MacrosHelpers.TwoTwoDiff(bdyt_adx1, bdyt_adx0, bdxt_ady1, bdxt_ady0, out bt_a[3], out bt_a[2], out bt_a[1], out bt_a[0]); bt_alen = 4; } } double[] ct_a = new double[4]; double[] ct_b = new double[4]; int ct_alen; int ct_blen; if (cdxtail == 0.0) { if (cdytail == 0.0) { ct_a[0] = 0.0; ct_alen = 1; ct_b[0] = 0.0; ct_blen = 1; } else { var negate = -cdytail; MacrosHelpers.TwoProduct(negate, adx, out ct_a[1], out ct_a[0]); ct_alen = 2; MacrosHelpers.TwoProduct(cdytail, bdx, out ct_b[1], out ct_b[0]); ct_blen = 2; } } else { if (cdytail == 0.0) { MacrosHelpers.TwoProduct(cdxtail, ady, out ct_a[1], out ct_a[0]); ct_alen = 2; var negate = -cdxtail; MacrosHelpers.TwoProduct(negate, bdy, out ct_b[1], out ct_b[0]); ct_blen = 2; } else { MacrosHelpers.TwoProduct(cdxtail, ady, out double cdxt_ady1, out double cdxt_ady0); MacrosHelpers.TwoProduct(cdytail, adx, out double cdyt_adx1, out double cdyt_adx0); MacrosHelpers.TwoTwoDiff(cdxt_ady1, cdxt_ady0, cdyt_adx1, cdyt_adx0, out ct_a[3], out ct_a[2], out ct_a[1], out ct_a[0]); ct_alen = 4; MacrosHelpers.TwoProduct(cdytail, bdx, out double cdyt_bdx1, out double cdyt_bdx0); MacrosHelpers.TwoProduct(cdxtail, bdy, out double cdxt_bdy1, out double cdxt_bdy0); MacrosHelpers.TwoTwoDiff(cdyt_bdx1, cdyt_bdx0, cdxt_bdy1, cdxt_bdy0, out ct_b[3], out ct_b[2], out ct_b[1], out ct_b[0]); ct_blen = 4; } } double[] bct = new double[8]; var bctlen = ArithmeticFunctions.FastExpansionSumZeroelim(bt_clen, bt_c, ct_blen, ct_b, bct); double[] u = new double[4]; double[] v = new double[12]; double[] w = new double[16]; var wlength = ArithmeticFunctions.ScaleExpansionZeroelim(bctlen, bct, adz, w); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, wlength, w, finother); var finswap = finnow; finnow = finother; finother = finswap; double[] cat = new double[8]; var catlen = ArithmeticFunctions.FastExpansionSumZeroelim(ct_alen, ct_a, at_clen, at_c, cat); wlength = ArithmeticFunctions.ScaleExpansionZeroelim(catlen, cat, bdz, w); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, wlength, w, finother); finswap = finnow; finnow = finother; finother = finswap; double[] abt = new double[8]; var abtlen = ArithmeticFunctions.FastExpansionSumZeroelim(at_blen, at_b, bt_alen, bt_a, abt); wlength = ArithmeticFunctions.ScaleExpansionZeroelim(abtlen, abt, cdz, w); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, wlength, w, finother); finswap = finnow; finnow = finother; finother = finswap; if (adztail != 0.0) { var vlength = ArithmeticFunctions.ScaleExpansionZeroelim(4, bc, adztail, v); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, vlength, v, finother); finswap = finnow; finnow = finother; finother = finswap; } if (bdztail != 0.0) { var vlength = ArithmeticFunctions.ScaleExpansionZeroelim(4, ca, bdztail, v); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, vlength, v, finother); finswap = finnow; finnow = finother; finother = finswap; } if (cdztail != 0.0) { var vlength = ArithmeticFunctions.ScaleExpansionZeroelim(4, ab, cdztail, v); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, vlength, v, finother); finswap = finnow; finnow = finother; finother = finswap; } if (adxtail != 0.0) { if (bdytail != 0.0) { MacrosHelpers.TwoProduct(adxtail, bdytail, out double adxt_bdyt1, out double adxt_bdyt0); MacrosHelpers.TwoOneProduct(adxt_bdyt1, adxt_bdyt0, cdz, out u[3], out u[2], out u[1], out u[0]); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; if (cdztail != 0.0) { MacrosHelpers.TwoOneProduct(adxt_bdyt1, adxt_bdyt0, cdztail, out u[3], out u[2], out u[1], out u[0]); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; } } if (cdytail != 0.0) { var negate = -adxtail; MacrosHelpers.TwoProduct(negate, cdytail, out double adxt_cdyt1, out double adxt_cdyt0); MacrosHelpers.TwoOneProduct(adxt_cdyt1, adxt_cdyt0, bdz, out u[3], out u[2], out u[1], out u[0]); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; if (bdztail != 0.0) { MacrosHelpers.TwoOneProduct(adxt_cdyt1, adxt_cdyt0, bdztail, out u[3], out u[2], out u[1], out u[0]); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; } } } if (bdxtail != 0.0) { if (cdytail != 0.0) { MacrosHelpers.TwoProduct(bdxtail, cdytail, out double bdxt_cdyt1, out double bdxt_cdyt0); MacrosHelpers.TwoOneProduct(bdxt_cdyt1, bdxt_cdyt0, adz, out u[3], out u[2], out u[1], out u[0]); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; if (adztail != 0.0) { MacrosHelpers.TwoOneProduct(bdxt_cdyt1, bdxt_cdyt0, adztail, out u[3], out u[2], out u[1], out u[0]); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; } } if (adytail != 0.0) { var negate = -bdxtail; MacrosHelpers.TwoProduct(negate, adytail, out double bdxt_adyt1, out double bdxt_adyt0); MacrosHelpers.TwoOneProduct(bdxt_adyt1, bdxt_adyt0, cdz, out u[3], out u[2], out u[1], out u[0]); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; if (cdztail != 0.0) { MacrosHelpers.TwoOneProduct(bdxt_adyt1, bdxt_adyt0, cdztail, out u[3], out u[2], out u[1], out u[0]); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; } } } if (cdxtail != 0.0) { if (adytail != 0.0) { MacrosHelpers.TwoProduct(cdxtail, adytail, out double cdxt_adyt1, out double cdxt_adyt0); MacrosHelpers.TwoOneProduct(cdxt_adyt1, cdxt_adyt0, bdz, out u[3], out u[2], out u[1], out u[0]); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; if (bdztail != 0.0) { MacrosHelpers.TwoOneProduct(cdxt_adyt1, cdxt_adyt0, bdztail, out u[3], out u[2], out u[1], out u[0]); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; } } if (bdytail != 0.0) { var negate = -cdxtail; MacrosHelpers.TwoProduct(negate, bdytail, out double cdxt_bdyt1, out double cdxt_bdyt0); MacrosHelpers.TwoOneProduct(cdxt_bdyt1, cdxt_bdyt0, adz, out u[3], out u[2], out u[1], out u[0]); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; if (adztail != 0.0) { MacrosHelpers.TwoOneProduct(cdxt_bdyt1, cdxt_bdyt0, adztail, out u[3], out u[2], out u[1], out u[0]); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; } } } if (adztail != 0.0) { wlength = ArithmeticFunctions.ScaleExpansionZeroelim(bctlen, bct, adztail, w); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, wlength, w, finother); finswap = finnow; finnow = finother; finother = finswap; } if (bdztail != 0.0) { wlength = ArithmeticFunctions.ScaleExpansionZeroelim(catlen, cat, bdztail, w); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, wlength, w, finother); finswap = finnow; finnow = finother; finother = finswap; } if (cdztail != 0.0) { wlength = ArithmeticFunctions.ScaleExpansionZeroelim(abtlen, abt, cdztail, w); finlength = ArithmeticFunctions.FastExpansionSumZeroelim(finlength, finnow, wlength, w, finother); finswap = finnow; finnow = finother; finother = finswap; } return(finnow[finlength - 1]); }
private static double Adapt(double[] pa, double[] pb, double[] pc, double detsum) { double acx = pa[0] - pc[0]; double bcx = pb[0] - pc[0]; double acy = pa[1] - pc[1]; double bcy = pb[1] - pc[1]; MacrosHelpers.TwoProduct(acx, bcy, out double detleft, out double detlefttail); MacrosHelpers.TwoProduct(acy, bcx, out double detright, out double detrighttail); double[] B = new double[4]; MacrosHelpers.TwoTwoDiff(detleft, detlefttail, detright, detrighttail, out B[3], out B[2], out B[1], out B[0]); double det = ArithmeticFunctions.Estimate(4, B); double errbound = MacrosHelpers.CcwerrboundB * detsum; if ((det >= errbound) || (-det >= errbound)) { return(det); } MacrosHelpers.TwoDiffTail(pa[0], pc[0], acx, out double acxtail); MacrosHelpers.TwoDiffTail(pb[0], pc[0], bcx, out double bcxtail); MacrosHelpers.TwoDiffTail(pa[1], pc[1], acy, out double acytail); MacrosHelpers.TwoDiffTail(pb[1], pc[1], bcy, out double bcytail); if ((acxtail == 0.0) && (acytail == 0.0) && (bcxtail == 0.0) && (bcytail == 0.0)) { return(det); } errbound = MacrosHelpers.CcwerrboundC * detsum + MacrosHelpers.Resulterrbound * Math.Abs(det); det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail); if ((det >= errbound) || (-det >= errbound)) { return(det); } double[] u = new double[4]; MacrosHelpers.TwoProduct(acxtail, bcy, out double s1, out double s0); MacrosHelpers.TwoProduct(acytail, bcx, out double t1, out double t0); MacrosHelpers.TwoTwoDiff(s1, s0, t1, t0, out u[3], out u[2], out u[1], out u[0]); double[] C1 = new double[8]; int C1length = ArithmeticFunctions.FastExpansionSumZeroelim(4, B, 4, u, C1); MacrosHelpers.TwoProduct(acx, bcytail, out s1, out s0); MacrosHelpers.TwoProduct(acy, bcxtail, out t1, out t0); MacrosHelpers.TwoTwoDiff(s1, s0, t1, t0, out u[3], out u[2], out u[1], out u[0]); double[] C2 = new double[12]; int C2length = ArithmeticFunctions.FastExpansionSumZeroelim(C1length, C1, 4, u, C2); MacrosHelpers.TwoProduct(acxtail, bcytail, out s1, out s0); MacrosHelpers.TwoProduct(acytail, bcxtail, out t1, out t0); MacrosHelpers.TwoTwoDiff(s1, s0, t1, t0, out u[3], out u[2], out u[1], out u[0]); double[] D = new double[16]; int Dlength = ArithmeticFunctions.FastExpansionSumZeroelim(C2length, C2, 4, u, D); return(D[Dlength - 1]); }