Here you can find the source of sqrt(BigDecimal value, MathContext mc)
Parameter | Description |
---|---|
value | a parameter |
mc | a parameter |
public static final BigDecimal sqrt(BigDecimal value, MathContext mc)
//package com.java2s; /*/*from w w w . j a va2 s .com*/ * Copyright 2014 Jon N. Marsh. * Because small portions of this software are derived from Apache Commons Math * and GNU Scientific Library routines, it is licensed under GPLv3, which is * compatible with Apache Software License 2.0: * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. */ import java.math.BigDecimal; import java.math.MathContext; public class Main { /** * Extra precise sqrt function for use with BigDecimal class. Uses Newton's * method to roughly double the number of significant digits of typical * floating-point sqrt function. (This gem was found on StackOverflow.com) * * @param value * @param mc * @return square root of {@code value} */ public static final BigDecimal sqrt(BigDecimal value, MathContext mc) { BigDecimal x = new BigDecimal(Math.sqrt(value.doubleValue()), mc); return x.add(new BigDecimal(value.subtract(x.multiply(x)).doubleValue() / (x.doubleValue() * 2.0), mc)); } }