// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class MoreSqrt {
    public static void test(double x) {
        double res;
        // newtons methods
        res = 0.5*x;
        for(int i = 0; i < 10; i++) {
            res = 0.5*(res + x/res);
            System.out.println((i + 1) + " " + Math.abs(1 - res/Math.sqrt(x)));
        }
        // taylor series
        res = 0;
        double c = 1;
        double f = 1;
        double xa = 1;
        for(int i = 0; i < 25; i++) {
            res += c / f * xa;
            c *= (0.5 - i);
            f *= (i + 1);
            xa *= (x - 1);
            System.out.println((i + 1) + " " + Math.abs(1 - res/Math.sqrt(x)));
        }
    }
    public static void main(String[] args) {
        test(1.5);
    }
}
