List of usage examples for java.lang Math sqrt
@HotSpotIntrinsicCandidate public static double sqrt(double a)
From source file:Main.java
public static Bitmap resizeDownToPixels(Bitmap bitmap, int targetPixels, boolean recycle) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float scale = (float) Math.sqrt((double) targetPixels / (width * height)); if (scale >= 1.0f) return bitmap; return resizeBitmapByScale(bitmap, scale, recycle); }
From source file:Main.java
public static boolean isTablet(Context ctx) { try {//from ww w. j a v a 2 s .c om DisplayMetrics dm = ctx.getResources().getDisplayMetrics(); float screenWidth = dm.widthPixels / dm.xdpi; float screenHeight = dm.heightPixels / dm.ydpi; double size = Math.sqrt(Math.pow(screenWidth, 2) + Math.pow(screenHeight, 2)); return size >= 6; } catch (Throwable t) { return false; } }
From source file:Main.java
private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels < 0) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength < 0) ? 128 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { // return the larger one when there is no overlapping zone. return lowerBound; }/* www . j a v a2 s. c om*/ if (maxNumOfPixels < 0 && minSideLength < 0) { return 1; } else if (minSideLength < 0) { return lowerBound; } else { return upperBound; } }
From source file:Main.java
public static void transform(double wgLat, double wgLon, double[] latlng) { if (outOfChina(wgLat, wgLon)) { latlng[0] = wgLat;/*w w w . ja va2 s. c o m*/ latlng[1] = wgLon; return; } double dLat = transformLat(wgLon - 105.0, wgLat - 35.0); double dLon = transformLon(wgLon - 105.0, wgLat - 35.0); double radLat = wgLat / 180.0 * pi; double magic = Math.sin(radLat); magic = 1 - ee * magic * magic; double sqrtMagic = Math.sqrt(magic); dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi); latlng[0] = wgLat + dLat; latlng[1] = wgLon + dLon; }
From source file:Main.java
public static double getDistance(double lat1, double lng1, double lat2, double lng2) { double radLat1 = rad(lat1); double radLat2 = rad(lat2); double a = radLat1 - radLat2; double b = rad(lng1) - rad(lng2); double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); s = s * EARTH_RADIUS;//from w w w .j a v a 2s . c o m s = Math.round(s * 10000d) / 10000d; s = s * 1000; return s; }
From source file:IsPrimeOld.java
private static void initPrimeList() { long start = System.currentTimeMillis(); if (maxNumber == 3) { primeList.add(2L);/*from w w w. j av a 2 s .c om*/ primeList.add(3L); } for (long i = maxNumber; i < newMaxNumber; i += 2) { long j = 1; double temp = Math.sqrt(i); for (j = 2; j < temp; j++) { if (i % j == 0) break; } if (j == (long) temp + 1) { primeList.add(i); } } long end = System.currentTimeMillis(); maxNumber = newMaxNumber; }
From source file:Main.java
private static int computeInitialSampleSize(int w, int h, int minSideLength, int maxNumOfPixels) { if (maxNumOfPixels == UNCONSTRAINED && minSideLength == UNCONSTRAINED) return 1; int lowerBound = (maxNumOfPixels == UNCONSTRAINED) ? 1 : (int) Math.ceil(Math.sqrt((double) (w * h) / maxNumOfPixels)); if (minSideLength == UNCONSTRAINED) { return lowerBound; } else {/*w w w. j a v a 2s . c o m*/ int sampleSize = Math.min(w / minSideLength, h / minSideLength); return Math.max(sampleSize, lowerBound); } }
From source file:Main.java
private static int computeInitialSampleSize(int w, int h, int minSideLength, int maxNumOfPixels) { if (maxNumOfPixels == UNCONSTRAINED && minSideLength == UNCONSTRAINED) return 1; int lowerBound = (maxNumOfPixels == UNCONSTRAINED) ? 1 : (int) Math.ceil(Math.sqrt((float) (w * h) / maxNumOfPixels)); if (minSideLength == UNCONSTRAINED) { return lowerBound; } else {//from w w w.j a va 2 s . com int sampleSize = Math.min(w / minSideLength, h / minSideLength); return Math.max(sampleSize, lowerBound); } }
From source file:Main.java
public static double confval(int N, double alfa, double std) { return zn(alfa) * (std / Math.sqrt((double) N)); }
From source file:Main.java
static public String whyNotPrimeNumber(int num) { if (num <= 0) { return "0 and negative numbers are not Prime"; }//from www . j a v a 2s . c om if (num == 1) { return "1 is not prime number"; } for (int i = (int) Math.sqrt(num); i > 1; i--) { if (num % i == 0) { return num + " = " + i + " X " + num / i; } } return null; }