int main() { // a is really close to 1.0, but has rounding errors, so it's slightly smaller than 1.0 double a = 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1; // First, let's compare a (almost 1.0) to 1.0. std::cout << approximatelyEqual(a, 1.0, 1e-12,1e-8) << "\n"; // Second, let's compare a-1.0 (almost 0.0) to 0.0 std::cout << approximatelyEqual(a-1.0, 0.0, 1e-12,1e-8) << "\n"; return 0; }
void setcoeffs(float freq,float t0,float ftN){ //if(this->freq == freq && this->t0 == t0 && this->ftN == ftN) if(approximatelyEqual(this->freq,freq) && approximatelyEqual(this->t0,t0) && approximatelyEqual(this->ftN,ftN)) return; //if(std::islessgreater(this->freq,freq) || std::islessgreater(this->t0,t0) || std::islessgreater(this->ftN,ftN)){ Print("this freq %g c1 %g c3 %g\n",this->freq - freq,this->t0-t0,this->ftN-ftN); this->t0 = t0; this->ftN = ftN; float c1 = 1/t0; float c3 = (1.0 - ftN)/(ftN*t0*M_PI*M_PI); Print("freq %g c1 %g c3 %g\n",freq,c1,c3); Print("this freq %g c1 %g c3 %g\n",this->freq - freq,this->t0-t0,this->ftN-ftN); FilterC1C3::setcoeffs(freq,c1,c3); //} }
static void Test_alpha_epsilon(void) { printf("\n** Test_alpha_epsilon: **\n"); const REAL8 f = 0.01; const REAL8 q = 4; const REAL8 chil = 0.5625; const REAL8 chip = 0.18; NNLOanglecoeffs angcoeffs; ComputeNNLOanglecoeffs(&angcoeffs,q,chil,chip); const REAL8 omega = LAL_PI * f; const REAL8 logomega = log(omega); const REAL8 omega_cbrt = cbrt(omega); const REAL8 omega_cbrt2 = omega_cbrt*omega_cbrt; const REAL8 alpha = (angcoeffs.alphacoeff1/omega + angcoeffs.alphacoeff2/omega_cbrt2 + angcoeffs.alphacoeff3/omega_cbrt + angcoeffs.alphacoeff4*logomega + angcoeffs.alphacoeff5*omega_cbrt); const REAL8 epsilon = (angcoeffs.epsiloncoeff1/omega + angcoeffs.epsiloncoeff2/omega_cbrt2 + angcoeffs.epsiloncoeff3/omega_cbrt + angcoeffs.epsiloncoeff4*logomega + angcoeffs.epsiloncoeff5*omega_cbrt); const REAL8 alpha_expected = -11.8196; const REAL8 epsilon_expected = -11.936; print_difference("alpha", alpha, alpha_expected); print_difference("epsilon", epsilon, epsilon_expected); const REAL8 eps = 1e-5; assert( approximatelyEqual(alpha, alpha_expected, eps) && approximatelyEqual(epsilon, epsilon_expected, eps) && "Test_alpha_epsilon()" ); }
void PathPaintEngine::drawPath(const QPainterPath& path) { if (!dev) return; if(!isCosmetic) { QList<QPolygonF> polys = path.toSubpathPolygons(); for (int i = 0; i < polys.size(); ++i) { if(dashPattern.empty()) dev->addPath(transform.map(polys[i])); else { QPolygonF polytemp = transform.map(polys[i]), newpoly; int dashtoggle = 1, dashi=0, j = 0; qreal actualdashsize = dashPattern[dashi]; QPointF origin = QPointF(polytemp[j]), testp; j++; do { newpoly = QPolygonF(); newpoly.append(origin); do { testp = polytemp[j]; origin = QPointF(getPointAtLenght(QPointF(origin), polytemp[j], actualdashsize)); if (essentiallyEqual(origin.x(), polytemp[j].x(), 0.01 ) && approximatelyEqual(origin.y(), polytemp[j].y(),0.01) && j+1 < polytemp.size()) { origin = polytemp[j]; j++; testp = polytemp[j]; } newpoly.append(origin); }while(definitelyGreaterThan(actualdashsize,0.0,0.1) && testp!=origin); if(dashtoggle == 1) { dev->addPath(newpoly); } dashtoggle = dashtoggle * -1; dashi++; if(dashi >= dashPattern.size()) dashi=0; actualdashsize = dashPattern[dashi]; }while(!essentiallyEqual(origin.x(), polytemp[j].x(), 0.001 ) || !essentiallyEqual(origin.y(), polytemp[j].y(),0.001)); } } } }
static void Test_XLALSimIMRPhenomPCalculateModelParameters(void) { printf("\n** Test_XLALSimIMRPhenomPCalculateModelParameters: **\n"); REAL8 eta, chi_eff, chip, thetaJ, phiJ, alpha0; REAL8 m1_SI = 10 * LAL_MSUN_SI; REAL8 m2_SI = 40 * LAL_MSUN_SI; REAL8 s1x = 0.3; REAL8 s1y = 0; REAL8 s1z = 0.45; REAL8 s2x = 0; REAL8 s2y = 0; REAL8 s2z = 0.45; REAL8 lnhatx = sin(0.4); REAL8 lnhaty = 0; REAL8 lnhatz = cos(0.4); REAL8 f_min = 20; XLALSimIMRPhenomPCalculateModelParameters( &chi_eff, /**< Output: Effective aligned spin */ &chip, /**< Output: Effective spin in the orbital plane */ &eta, /**< Output: Symmetric mass-ratio */ &thetaJ, /**< Output: Angle between J0 and line of sight (z-direction) */ &phiJ, /**< Output: Angle of J0 in the plane of the sky */ &alpha0, /**< Output: Initial value of alpha angle */ m1_SI, /**< Mass of companion 1 (kg) */ m2_SI, /**< Mass of companion 2 (kg) */ f_min, /**< Starting GW frequency (Hz) */ lnhatx, /**< Initial value of LNhatx: orbital angular momentum unit vector */ lnhaty, /**< Initial value of LNhaty */ lnhatz, /**< Initial value of LNhatz */ s1x, /**< Initial value of s1x: dimensionless spin of larger BH */ s1y, /**< Initial value of s1y: dimensionless spin of larger BH */ s1z, /**< Initial value of s1z: dimensionless spin of larger BH */ s2x, /**< Initial value of s2x: dimensionless spin of larger BH */ s2y, /**< Initial value of s2y: dimensionless spin of larger BH */ s2z); /**< Initial value of s2z: dimensionless spin of larger BH */ REAL8 eta_expected = 0.16; REAL8 chi_eff_expected = 0.437843; REAL8 chip_expected = 0.175238; REAL8 thetaJ_expected = 0.298553; REAL8 phiJ_expected = 0; REAL8 alpha0_expected = 0; print_difference("eta", eta, eta_expected); print_difference("chi_eff", chi_eff, chi_eff_expected); print_difference("chip", chip, chip_expected); print_difference("thetaJ", thetaJ, thetaJ_expected); print_difference("phiJ", phiJ, phiJ_expected); print_difference("alpha0", alpha0, alpha0_expected); //const REAL8 eps = DBL_EPSILON; const REAL8 eps = 1e-5; assert( approximatelyEqual(eta, eta_expected, eps) && approximatelyEqual(chi_eff, chi_eff_expected, eps) && approximatelyEqual(chip, chip_expected, eps) && approximatelyEqual(thetaJ, thetaJ_expected, eps) && approximatelyEqual(phiJ, phiJ_expected, eps) && approximatelyEqual(alpha0, alpha0_expected, eps) && "Test_XLALSimIMRPhenomPCalculateModelParameters()" ); }
bool approximatelyEqualC(COMPLEX16 a, COMPLEX16 b, REAL8 epsilon) { return approximatelyEqual(creal(a), creal(b), epsilon) && approximatelyEqual(cimag(a), cimag(b), epsilon); }
/* check start and end of each contour if not the same, record them match them up connect closest reassemble contour pieces into new path */ void Assemble(const SkPathWriter& path, SkPathWriter* simple) { #if DEBUG_PATH_CONSTRUCTION SkDebugf("%s\n", __FUNCTION__); #endif SkTArray<SkOpContour> contours; SkOpEdgeBuilder builder(path, contours); builder.finish(); int count = contours.count(); int outer; SkTArray<int, true> runs(count); // indices of partial contours for (outer = 0; outer < count; ++outer) { const SkOpContour& eContour = contours[outer]; const SkPoint& eStart = eContour.start(); const SkPoint& eEnd = eContour.end(); #if DEBUG_ASSEMBLE SkDebugf("%s contour", __FUNCTION__); if (!approximatelyEqual(eStart, eEnd)) { SkDebugf("[%d]", runs.count()); } else { SkDebugf(" "); } SkDebugf(" start=(%1.9g,%1.9g) end=(%1.9g,%1.9g)\n", eStart.fX, eStart.fY, eEnd.fX, eEnd.fY); #endif if (approximatelyEqual(eStart, eEnd)) { eContour.toPath(simple); continue; } runs.push_back(outer); } count = runs.count(); if (count == 0) { return; } SkTArray<int, true> sLink, eLink; sLink.push_back_n(count); eLink.push_back_n(count); int rIndex, iIndex; for (rIndex = 0; rIndex < count; ++rIndex) { sLink[rIndex] = eLink[rIndex] = SK_MaxS32; } const int ends = count * 2; // all starts and ends const int entries = (ends - 1) * count; // folded triangle : n * (n - 1) / 2 SkTArray<double, true> distances; distances.push_back_n(entries); for (rIndex = 0; rIndex < ends - 1; ++rIndex) { outer = runs[rIndex >> 1]; const SkOpContour& oContour = contours[outer]; const SkPoint& oPt = rIndex & 1 ? oContour.end() : oContour.start(); const int row = rIndex < count - 1 ? rIndex * ends : (ends - rIndex - 2) * ends - rIndex - 1; for (iIndex = rIndex + 1; iIndex < ends; ++iIndex) { int inner = runs[iIndex >> 1]; const SkOpContour& iContour = contours[inner]; const SkPoint& iPt = iIndex & 1 ? iContour.end() : iContour.start(); double dx = iPt.fX - oPt.fX; double dy = iPt.fY - oPt.fY; double dist = dx * dx + dy * dy; distances[row + iIndex] = dist; // oStart distance from iStart } } SkTArray<int, true> sortedDist; sortedDist.push_back_n(entries); for (rIndex = 0; rIndex < entries; ++rIndex) { sortedDist[rIndex] = rIndex; } SkTQSort<int>(sortedDist.begin(), sortedDist.end() - 1, DistanceLessThan(distances.begin())); int remaining = count; // number of start/end pairs for (rIndex = 0; rIndex < entries; ++rIndex) { int pair = sortedDist[rIndex]; int row = pair / ends; int col = pair - row * ends; int thingOne = row < col ? row : ends - row - 2; int ndxOne = thingOne >> 1; bool endOne = thingOne & 1; int* linkOne = endOne ? eLink.begin() : sLink.begin(); if (linkOne[ndxOne] != SK_MaxS32) { continue; } int thingTwo = row < col ? col : ends - row + col - 1; int ndxTwo = thingTwo >> 1; bool endTwo = thingTwo & 1; int* linkTwo = endTwo ? eLink.begin() : sLink.begin(); if (linkTwo[ndxTwo] != SK_MaxS32) { continue; } SkASSERT(&linkOne[ndxOne] != &linkTwo[ndxTwo]); bool flip = endOne == endTwo; linkOne[ndxOne] = flip ? ~ndxTwo : ndxTwo; linkTwo[ndxTwo] = flip ? ~ndxOne : ndxOne; if (!--remaining) { break; } } SkASSERT(!remaining); #if DEBUG_ASSEMBLE for (rIndex = 0; rIndex < count; ++rIndex) { int s = sLink[rIndex]; int e = eLink[rIndex]; SkDebugf("%s %c%d <- s%d - e%d -> %c%d\n", __FUNCTION__, s < 0 ? 's' : 'e', s < 0 ? ~s : s, rIndex, rIndex, e < 0 ? 'e' : 's', e < 0 ? ~e : e); } #endif rIndex = 0; do { bool forward = true; bool first = true; int sIndex = sLink[rIndex]; SkASSERT(sIndex != SK_MaxS32); sLink[rIndex] = SK_MaxS32; int eIndex; if (sIndex < 0) { eIndex = sLink[~sIndex]; sLink[~sIndex] = SK_MaxS32; } else { eIndex = eLink[sIndex]; eLink[sIndex] = SK_MaxS32; } SkASSERT(eIndex != SK_MaxS32); #if DEBUG_ASSEMBLE SkDebugf("%s sIndex=%c%d eIndex=%c%d\n", __FUNCTION__, sIndex < 0 ? 's' : 'e', sIndex < 0 ? ~sIndex : sIndex, eIndex < 0 ? 's' : 'e', eIndex < 0 ? ~eIndex : eIndex); #endif do { outer = runs[rIndex]; const SkOpContour& contour = contours[outer]; if (first) { first = false; const SkPoint* startPtr = &contour.start(); simple->deferredMove(startPtr[0]); } if (forward) { contour.toPartialForward(simple); } else { contour.toPartialBackward(simple); } #if DEBUG_ASSEMBLE SkDebugf("%s rIndex=%d eIndex=%s%d close=%d\n", __FUNCTION__, rIndex, eIndex < 0 ? "~" : "", eIndex < 0 ? ~eIndex : eIndex, sIndex == ((rIndex != eIndex) ^ forward ? eIndex : ~eIndex)); #endif if (sIndex == ((rIndex != eIndex) ^ forward ? eIndex : ~eIndex)) { simple->close(); break; } if (forward) { eIndex = eLink[rIndex]; SkASSERT(eIndex != SK_MaxS32); eLink[rIndex] = SK_MaxS32; if (eIndex >= 0) { SkASSERT(sLink[eIndex] == rIndex); sLink[eIndex] = SK_MaxS32; } else { SkASSERT(eLink[~eIndex] == ~rIndex); eLink[~eIndex] = SK_MaxS32; } } else { eIndex = sLink[rIndex]; SkASSERT(eIndex != SK_MaxS32); sLink[rIndex] = SK_MaxS32; if (eIndex >= 0) { SkASSERT(eLink[eIndex] == rIndex); eLink[eIndex] = SK_MaxS32; } else { SkASSERT(sLink[~eIndex] == ~rIndex); sLink[~eIndex] = SK_MaxS32; } } rIndex = eIndex; if (rIndex < 0) { forward ^= 1; rIndex = ~rIndex; } } while (true); for (rIndex = 0; rIndex < count; ++rIndex) { if (sLink[rIndex] != SK_MaxS32) { break; } } } while (rIndex < count); #if DEBUG_ASSEMBLE for (rIndex = 0; rIndex < count; ++rIndex) { SkASSERT(sLink[rIndex] == SK_MaxS32); SkASSERT(eLink[rIndex] == SK_MaxS32); } #endif }