Search in sources :

Example 6 with DD

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

the class DDBasicTest method checkTrunc.

private void checkTrunc(final DD x, final DD expected) {
    final DD trunc = x.trunc();
    final boolean isEqual = trunc.equals(expected);
    assertTrue(isEqual);
}
Also used : DD(com.revolsys.geometry.math.DD)

Example 7 with DD

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

the class DDBasicTest method slowPow.

private DD slowPow(final DD x, final int exp) {
    if (exp == 0) {
        return DD.valueOf(1.0);
    }
    final 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;
}
Also used : DD(com.revolsys.geometry.math.DD)

Example 8 with DD

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

the class DDComputeTest method computePiByMachin.

/**
 * 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() {
    final DD t1 = DD.valueOf(1.0).divide(DD.valueOf(5.0));
    final DD t2 = DD.valueOf(1.0).divide(DD.valueOf(239.0));
    final DD pi4 = DD.valueOf(4.0).multiply(arctan(t1)).subtract(arctan(t2));
    final DD pi = DD.valueOf(4.0).multiply(pi4);
    // System.out.println("Computed value = " + pi);
    return pi;
}
Also used : DD(com.revolsys.geometry.math.DD)

Example 9 with DD

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

the class DDComputeTest method arctan.

/**
 * Computes the arctangent based on the Taylor series expansion
 *
 *    arctan(x) = x - x^3 / 3 + x^5 / 5 - x^7 / 7 + ...
 *
 * @param x the argument
 * @return an approximation to the arctangent of the input
 */
private DD arctan(final DD x) {
    DD t = x;
    final DD t2 = t.sqr();
    DD at = new DD(0.0);
    final DD two = new DD(2.0);
    int k = 0;
    DD d = new DD(1.0);
    int sign = 1;
    while (t.doubleValue() > DD.EPS) {
        k++;
        if (sign < 0) {
            at = at.subtract(t.divide(d));
        } else {
            at = at.add(t.divide(d));
        }
        d = d.add(two);
        t = t.multiply(t2);
        sign = -sign;
    }
    // + Math.atan(x.doubleValue()));
    return at;
}
Also used : DD(com.revolsys.geometry.math.DD)

Example 10 with DD

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

the class DDExpressionPerf method xrunDoubleDoubleSelf.

// */
public double xrunDoubleDoubleSelf(final int nIter) {
    final Stopwatch sw = new Stopwatch();
    for (int i = 0; i < nIter; i++) {
        final DD a = new DD(9.0);
        final DD factor = new DD(10.0);
        final DD aMul = factor.multiply(a);
        final DD aDiv = a.divide(factor);
        final DD det = a.multiply(a).subtract(aMul.multiply(aDiv));
    // System.out.println(aDiv);
    // System.out.println(det);
    }
    sw.stop();
    // + sw.getTimeString());
    return sw.getTime() / (double) nIter;
}
Also used : DD(com.revolsys.geometry.math.DD) Stopwatch(com.revolsys.geometry.util.Stopwatch)

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