/** * Creates a new DoubleDouble with value equal to the argument. * * @param str the value to initialize by * @throws NumberFormatException if <tt>str</tt> is not a valid representation of a number */ public DD(String str) throws NumberFormatException { this(parse(str)); }
/** * Converts the string argument to a DoubleDouble number. * * @param str a string containing a representation of a numeric value * @return the extended precision version of the value * @throws NumberFormatException if <tt>s</tt> is not a valid representation of a number */ public static DD valueOf(String str) throws NumberFormatException { return parse(str); }
private void checkParseError(String str) { boolean foundParseError = false; try { DD.parse(str); } catch (NumberFormatException ex) { foundParseError = true; } assertTrue(foundParseError); }
/** * Tests that printing values with many decimal places works. * This tests the correctness and robustness of both output and input. * * @param x the value to test */ private void writeAndReadSqrt(double x) { DD xdd = DD.valueOf(x); DD xSqrt = xdd.sqrt(); String s = xSqrt.toString(); // System.out.println(s); DD xSqrt2 = DD.parse(s); DD xx = xSqrt2.multiply(xSqrt2); String xxStr = xx.toString(); // System.out.println("==> " + xxStr); DD xx2 = DD.parse(xxStr); double err = Math.abs(xx2.doubleValue() - x); assertTrue(err < 1e-10); }
private void checkParse(String str, DD expectedVal, double relErrBound) { DD xdd = DD.parse(str); double err = xdd.subtract(expectedVal).doubleValue(); double xddd = xdd.doubleValue(); double relErr = xddd == 0d ? err : Math.abs(err / xddd); //System.out.println("Parsed= " + xdd + " rel err= " + relErr); assertTrue("parsing '" + str + "' results in " + xdd.toString() + " ( " + xdd.dump() + ") != " + expectedVal + "\n err =" + err + ", relerr =" + relErr, relErr <= relErrBound); }
/** * This routine simply tests for robustness of the toString function. * * @param xdd the value to test (write and parse) */ private void writeRepeatedSqr(DD xdd) { if (xdd.ge(DD.valueOf(1))) throw new IllegalArgumentException("Argument must be < 1"); int count = 0; while (xdd.doubleValue() > 1e-300) { count++; if (count == 100) count = count; double x = xdd.doubleValue(); DD xSqr = xdd.sqr(); String s = xSqr.toString(); //System.out.println(count + ": " + s); DD xSqr2 = DD.parse(s); xdd = xSqr; } }
DD xSqrt2 = DD.parse(s); DD xx = xSqrt2.multiply(xSqrt2); double err = Math.abs(xx.doubleValue() - x);