Java sqr sqrt(int val)

Here you can find the source of sqrt(int val)

Description

sqrt

License

Open Source License

Declaration

public static int sqrt(int val) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int sqrt(int val) {
        //      using estimate method from http://www.azillionmonkeys.com/qed/sqroot.html 
        //      System.out.print(val + ", " + (int)Math.sqrt(val) + ", "); 
        int temp, g = 0, b = 0x8000, bshft = 15;
        do {// w w w  .j av  a 2  s.  co m
            if (val >= (temp = (((g << 1) + b) << bshft--))) {
                g += b;
                val -= temp;
            }
        } while ((b >>= 1) > 0);

        return g;
    }
}

Related

  1. sqrt(final double x)
  2. sqrt(float a)
  3. sqrt(float a)
  4. sqrt(float f)
  5. sqrt(int n)
  6. sqrt(long val)
  7. sqrt(long x)
  8. sqrt(Short a)
  9. sqrt(short value)