Here you can find the source of sqrt(double x, int precision)
public static double sqrt(double x, int precision)
//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; } }