public static double ln(double x) {
        boolean negative = false;

        if (x < 0) {
            return Double.NaN;
        }
        if (x == 0) {
            return Double.NEGATIVE_INFINITY;
        }
        if (Double.isInfinite(x)) {
            return Double.POSITIVE_INFINITY;
        }
        if (x < 1) {
            negative = true;
            x = 1 / x;
        }
        int multiplier = 1;

         // x must be between 0 and 2 - close to 1 means faster taylor expansion
        while (x >= 1.1) {
            multiplier *= 2;
            x = Math.sqrt(x);
        }
        double t = 1 - x;
        double tpow = t;
        int divisor = 1;
        double result = 0;

        double toSubtract;
        while (Math.abs((toSubtract = tpow / divisor)) > EPS) {
            result -= toSubtract;
            tpow *= t;
            divisor++;
        }
        double res = multiplier * result;
        if (negative) {
            return -res;
        }
        return res;
    }
Rounds to keep <em>precision</em> decimals. Rounds towards even numbers.
@param x the number to round
@param precision the precision to round to. A precision of 3 will for instance round 1.65432 to 1.654
@return the rounded number
main/src/main/java/cgeo/geocaching/wherigo/kahlua/stdlib/MathLib.java