Java sqr sqrt(double x, int precision)

Here you can find the source of sqrt(double x, int precision)

Description

sqrt

License

Open Source License

Declaration

public static double sqrt(double x, int precision) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009 /*w  w  w .j  a v a 2  s  . c o m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Agustin Rodr?guez killgt@gmail.com
 ******************************************************************************/

public class Main {
    public static double sqrt(double x, int precision) {
        if (x == 0)
            return 0;
        double root = x / 2;
        for (int k = 0; k < precision; k++)
            root = (root + (x / root)) / 2;
        return root;
    }
}

Related

  1. sqrt(double a)
  2. sqrt(double d)
  3. sqrt(double n)
  4. sqrt(double value)
  5. sqrt(double value)
  6. sqrt(final double i)
  7. sqrt(final double x)
  8. sqrt(float a)
  9. sqrt(float a)