val2 = val.divide(scale);
private void checkMultiplyDivide(DD a, DD b, double errBound) { DD a2 = a.multiply(b).divide(b); checkErrorBound("MultiplyDivide", a, a2, errBound); }
private void checkDivideMultiply(DD a, DD b, double errBound) { DD a2 = a.divide(b).multiply(b); checkErrorBound("DivideMultiply", a, a2, errBound); }
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); }
public void testWriteRepeatedSqr() { writeRepeatedSqr(DD.valueOf(.9)); writeRepeatedSqr(DD.PI.divide(DD.valueOf(10))); }
public void testWriteRepeatedSqrt() { writeRepeatedSqrt(DD.valueOf(1.0)); writeRepeatedSqrt(DD.valueOf(.999999999999)); writeRepeatedSqrt(DD.PI.divide(DD.valueOf(10))); }
/** * 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; }
/** * Uses Taylor series to compute e * * e = 1 + 1 + 1/2! + 1/3! + 1/4! + ... * * @return an approximation to e */ private DD computeEByTaylorSeries() { DD s = DD.valueOf(2.0); DD t = DD.valueOf(1.0); double n = 1.0; int i = 0; while (t.doubleValue() > DD.EPS) { i++; n += 1.0; t = t.divide(DD.valueOf(n)); s = s.add(t); //System.out.println(i + ": " + s); } return s; }
public void testWriteSciNotation() { checkSciNotation(0.0, "0.0E0"); checkSciNotation(1.05e10, "1.05E10"); checkSciNotation(0.34, "3.4000000000000002442490654175344E-1"); checkSciNotation( DD.valueOf(34).divide(DD.valueOf(100)), "3.4E-1"); checkSciNotation(14, "1.4E1"); }
public void testNaN() { assertTrue(DD.valueOf(1).divide(DD.valueOf(0)).isNaN()); assertTrue(DD.valueOf(1).multiply(DD.NaN).isNaN()); }
public double xrunDoubleDoubleSelf(int nIter) { Stopwatch sw = new Stopwatch(); for (int i = 0; i < nIter; i++) { DD a = new DD(9.0); DD factor = new DD(10.0); DD aMul = factor.multiply(a); DD aDiv = a.divide(factor); DD det = a.multiply(a) .subtract(aMul.multiply(aDiv)); // System.out.println(aDiv); // System.out.println(det); } sw.stop(); System.out.println("DD: nIter = " + nIter + " time = " + sw.getTimeString()); return sw.getTime() / (double) nIter; }
public double runDoubleDouble(int nIter) { Stopwatch sw = new Stopwatch(); for (int i = 0; i < nIter; i++) { DD a = new DD(9.0); DD factor = new DD(10.0); DD aMul = factor.multiply(a); DD aDiv = a.divide(factor); DD det = a.multiply(a) .subtract(aMul.multiply(aDiv)); // System.out.println(aDiv); // System.out.println(det); } sw.stop(); System.out.println("DD: nIter = " + nIter + " time = " + sw.getTimeString()); return sw.getTime() / (double) nIter; }
public void testWriteStandardNotation() { // standard cases checkStandardNotation(1.0, "1.0"); checkStandardNotation(0.0, "0.0"); // cases where hi is a power of 10 and lo is negative checkStandardNotation(DD.valueOf(1e12).subtract(DD.valueOf(1)), "999999999999.0"); checkStandardNotation(DD.valueOf(1e14).subtract(DD.valueOf(1)), "99999999999999.0"); checkStandardNotation(DD.valueOf(1e16).subtract(DD.valueOf(1)), "9999999999999999.0"); DD num8Dec = DD.valueOf(-379363639).divide( DD.valueOf(100000000)); checkStandardNotation(num8Dec, "-3.79363639"); checkStandardNotation(new DD(-3.79363639, 8.039137357367426E-17), "-3.7936363900000000000000000"); checkStandardNotation(DD.valueOf(34).divide( DD.valueOf(1000)), "0.034"); checkStandardNotation(1.05e3, "1050.0"); checkStandardNotation(0.34, "0.34000000000000002442490654175344"); checkStandardNotation(DD.valueOf(34).divide( DD.valueOf(100)), "0.34"); checkStandardNotation(14, "14.0"); }
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); }