public static DD sqrt(double x) { return valueOf(x).sqrt(); }
/** * Computes the square of this value. * * @return the square of this value. */ public static DD sqr(double x) { return valueOf(x).selfMultiply(x); }
public DD convert(double x) { return DD.valueOf(x + ""); } };
public DD convert(double x) { return DD.valueOf(x); } };
/** * Computes the sign of the determinant of the 2x2 matrix * with the given entries. * * @return -1 if the determinant is negative, * @return 1 if the determinant is positive, * @return 0 if the determinant is 0. */ public static int signOfDet2x2(double dx1, double dy1, double dx2, double dy2) { DD x1 = DD.valueOf(dx1); DD y1 = DD.valueOf(dy1); DD x2 = DD.valueOf(dx2); DD y2 = DD.valueOf(dy2); DD det = x1.multiply(y2).selfSubtract(y1.multiply(x2)); return det.signum(); }
public void testTrunc() { checkTrunc(DD.valueOf(1e16).subtract(DD.valueOf(1)), DD.valueOf(1e16).subtract(DD.valueOf(1))); // the appropriate error bound is determined empirically checkTrunc(DD.PI, DD.valueOf(3)); checkTrunc(DD.valueOf(999.999), DD.valueOf(999)); checkTrunc(DD.E.negate(), DD.valueOf(-2)); checkTrunc(DD.valueOf(-999.999), DD.valueOf(-999)); }
private void checkStandardNotation(double x, String expectedStr) { checkStandardNotation(DD.valueOf(x), expectedStr); }
private void checkSciNotation(double x, String expectedStr) { checkSciNotation(DD.valueOf(x), expectedStr); }
/** * Uses Machin's arctangent formula to compute Pi: * * Pi / 4 = 4 arctan(1/5) - arctan(1/239) * * @return an approximation to Pi */ private DD computePiByMachin() { DD t1 = DD.valueOf(1.0).divide(DD.valueOf(5.0)); DD t2 = DD.valueOf(1.0).divide(DD.valueOf(239.0)); DD pi4 = (DD.valueOf(4.0) .multiply(arctan(t1))) .subtract(arctan(t2)); DD pi = DD.valueOf(4.0).multiply(pi4); //System.out.println("Computed value = " + pi); return pi; }
public void testParseSciNotation() { checkParse("1.05e10", 1.05E10, 1e-32); checkParse("01.05e10", 1.05E10, 1e-32); checkParse("12.05e10", 1.205E11, 1e-32); checkParse("-1.05e10", -1.05E10, 1e-32); checkParse("1.05e-10", DD.valueOf(105.).divide( DD.valueOf(100.)).divide(DD.valueOf(1.0E10)), 1e-32); checkParse("-1.05e-10", DD.valueOf(105.).divide( DD.valueOf(100.)).divide(DD.valueOf(1.0E10)) .negate(), 1e-32); }
private DD slowPow(DD x, int exp) { if (exp == 0) return DD.valueOf(1.0); int n = Math.abs(exp); // MD - could use binary exponentiation for better precision & speed DD pow = new DD(x); for (int i = 1; i < n; i++) { pow = pow.multiply(x); } if (exp < 0) { return pow.reciprocal(); } return pow; }
public static boolean isInCircleDD3( Coordinate a, Coordinate b, Coordinate c, Coordinate p) { DD adx = DD.valueOf(a.x).selfSubtract(p.x); DD ady = DD.valueOf(a.y).selfSubtract(p.y); DD bdx = DD.valueOf(b.x).selfSubtract(p.x); DD bdy = DD.valueOf(b.y).selfSubtract(p.y); DD cdx = DD.valueOf(c.x).selfSubtract(p.x); DD cdy = DD.valueOf(c.y).selfSubtract(p.y); DD abdet = adx.multiply(bdy).selfSubtract(bdx.multiply(ady)); DD bcdet = bdx.multiply(cdy).selfSubtract(cdx.multiply(bdy)); DD cadet = cdx.multiply(ady).selfSubtract(adx.multiply(cdy)); DD alift = adx.multiply(adx).selfSubtract(ady.multiply(ady)); DD blift = bdx.multiply(bdx).selfSubtract(bdy.multiply(bdy)); DD clift = cdx.multiply(cdx).selfSubtract(cdy.multiply(cdy)); DD sum = alift.selfMultiply(bcdet) .selfAdd(blift.selfMultiply(cadet)) .selfAdd(clift.selfMultiply(abdet)); boolean isInCircle = sum.doubleValue() > 0; return isInCircle; }
public void testParseStandardNotation() { checkParse("1.0000000", 1, 1e-32); checkParse("1.0", 1, 1e-32); checkParse("1.", 1, 1e-32); checkParse("01.", 1, 1e-32); checkParse("-1.0", -1, 1e-32); checkParse("-1.", -1, 1e-32); checkParse("-01.0", -1, 1e-32); checkParse("-123.0", -123, 1e-32); /* * The Java double-precision constant 1.4 gives rise to a value which * differs from the exact binary representation down around the 17th decimal * place. Thus it will not compare exactly to the DoubleDouble * representation of the same number. To avoid this, compute the expected * value using full DD precision. */ checkParse("1.4", DD.valueOf(14).divide(DD.valueOf(10)), 1e-30); // 39.5D can be converted to an exact FP representation checkParse("39.5", 39.5, 1e-30); checkParse("-39.5", -39.5, 1e-30); }