org.metasyntactic.math
Class BigDecimalUtilities

java.lang.Object
  |
  +--org.metasyntactic.math.BigDecimalUtilities

public class BigDecimalUtilities
extends java.lang.Object


Method Summary
static void main(java.lang.String[] args)
           
static java.math.BigDecimal squareRoot(java.math.BigDecimal val)
          Use this algorithm to find the square root of any real number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

squareRoot

public static java.math.BigDecimal squareRoot(java.math.BigDecimal val)
Use this algorithm to find the square root of any real number. Step 1: Group the number in "twos" from the decimal place. (If you have a number with an odd number of digits, the group to the far left will only be a group of 1 digit.) Step 2: Start with the first group of two (the group on the left). This group may be a group of only one number if your number has an odd number of digits. Find the greatest square less than or equal to that group of digits and its square root will be your first approximation of the entire square root. Step 3: Subtract the current approximation squared and bring down the next group of numbers behind it. This is your next number to work with. Step 4: Double the current approximation of the root. Step 5: Find the "ones" digit of the doubled number that would result in a number which divides into the number you are currently working with- with the smallest possible remainder. This is the next number in your approximation of the square root. Step 6: Multiply the "ones" digit by the doubled number plus the "ones" digit. Subtract this number from the number you are currently working with and bring down the next group of numbers behind it. This is your next group of numbers to work with. Step 7: Repeat steps 4 through 6 until you get an approximation with an acceptable number of significant digits.


main

public static void main(java.lang.String[] args)