Search in sources :

Example 21 with DD

use of com.revolsys.geometry.math.DD in project com.revolsys.open by revolsys.

the class DDIOTest method writeAndReadSqrt.

/**
 * Tests that printing values with many decimal places works.
 * This tests the correctness and robustness of both output and input.
 *
 * @param x
 */
void writeAndReadSqrt(final double x) {
    final DD xdd = DD.valueOf(x);
    final DD xSqrt = xdd.sqrt();
    final String s = xSqrt.toString();
    // System.out.println(s);
    final DD xSqrt2 = DD.parse(s);
    final DD xx = xSqrt2.multiply(xSqrt2);
    final String xxStr = xx.toString();
    // System.out.println("==> " + xxStr);
    final DD xx2 = DD.parse(xxStr);
    final double err = Math.abs(xx2.doubleValue() - x);
    assertTrue(err < 1e-10);
}
Also used : DD(com.revolsys.geometry.math.DD)

Example 22 with DD

use of com.revolsys.geometry.math.DD in project com.revolsys.open by revolsys.

the class DDIOTest method writeRepeatedSqr.

/**
 * This routine simply tests for robustness of the toString function.
 *
 * @param xdd
 */
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;
        }
        final double x = xdd.doubleValue();
        final DD xSqr = xdd.sqr();
        final String s = xSqr.toString();
        // System.out.println(count + ": " + s);
        final DD xSqr2 = DD.parse(s);
        xdd = xSqr;
    }
}
Also used : DD(com.revolsys.geometry.math.DD)

Example 23 with DD

use of com.revolsys.geometry.math.DD in project com.revolsys.open by revolsys.

the class DDBasicTest method checkDivideMultiply.

private void checkDivideMultiply(final DD a, final DD b, final double errBound) {
    final DD a2 = a.divide(b).multiply(b);
    checkErrorBound("DivideMultiply", a, a2, errBound);
}
Also used : DD(com.revolsys.geometry.math.DD)

Example 24 with DD

use of com.revolsys.geometry.math.DD in project com.revolsys.open by revolsys.

the class DDBasicTest method checkErrorBound.

private void checkErrorBound(final String tag, final DD x, final DD y, final double errBound) {
    final DD err = x.subtract(y).abs();
    // System.out.println(tag + " err=" + err);
    final boolean isWithinEps = err.doubleValue() <= errBound;
    assertTrue(isWithinEps);
}
Also used : DD(com.revolsys.geometry.math.DD)

Example 25 with DD

use of com.revolsys.geometry.math.DD in project com.revolsys.open by revolsys.

the class DDBasicTest method checkMultiplyDivide.

private void checkMultiplyDivide(final DD a, final DD b, final double errBound) {
    final DD a2 = a.multiply(b).divide(b);
    checkErrorBound("MultiplyDivide", a, a2, errBound);
}
Also used : DD(com.revolsys.geometry.math.DD)

Aggregations

DD (com.revolsys.geometry.math.DD)34 Stopwatch (com.revolsys.geometry.util.Stopwatch)3 Point (com.revolsys.geometry.model.Point)1 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)1