List of usage examples for java.lang Math pow
@HotSpotIntrinsicCandidate public static double pow(double a, double b)
From source file:Main.java
public static String humanReadableByteCount(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); }
From source file:Main.java
public static double DistanceOfTwoPoints(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 ww. j a va2 s. co m*/ s = Math.round(s * 10000) / 10000; return s; }
From source file:Main.java
private static String humanReadableByteCount(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); }
From source file:Main.java
public static double distFrom(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 3958.75; double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double sindLat = Math.sin(dLat / 2); double sindLng = Math.sin(dLng / 2); double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double dist = earthRadius * c; if (dist >= 1000) { int distInInt = (int) dist; dist = (int) distInInt; } else if (dist >= 100) { dist = (((int) (dist * 10)) / 10.0); } else {//ww w .jav a 2 s . c o m dist = (((int) (dist * 100)) / 100.0); } return dist; }
From source file:Main.java
public static Bitmap createPOT(Bitmap bmp) { Bitmap potBmp = null;/*from w w w.j a v a 2 s . c o m*/ int potWidth = (int) Math.ceil(Math.log(bmp.getWidth()) / Math.log(2)); int potHeight = (int) Math.ceil(Math.log(bmp.getHeight()) / Math.log(2)); potHeight = (int) Math.pow(2, potHeight); potWidth = (int) Math.pow(2, potWidth); if (potWidth == 1) { potWidth = 2; } if (potHeight == 1) { potHeight = 2; } if (potHeight != bmp.getHeight() || potWidth != bmp.getWidth()) { int[] colors = new int[potWidth * potHeight]; int index = 0; int offset = potHeight - bmp.getHeight(); for (int i = 0; i < potHeight; i++) { for (int j = 0; j < potWidth; j++) { if (i > offset - 1) { if (j < bmp.getWidth() && i < bmp.getHeight()) { colors[index] = bmp.getPixel(j, i); } else { colors[index] = 0; } } index++; } } potBmp = Bitmap.createBitmap(colors, potWidth, potHeight, bmp.getConfig()); } else { potBmp = bmp; } System.gc(); return potBmp; }
From source file:Main.java
/** * Returns a number rounded off to the given number of decimals. * * @param value the value to round off. * @param decimals the number of decimals. * @return a number rounded off to the given number of decimals. *//*from w w w .ja va 2 s . c om*/ public static double getRounded(double value, int decimals) { final double factor = Math.pow(10, decimals); return Math.round(value * factor) / factor; }
From source file:Main.java
/** * Get the vectors magnitude.//from w w w .j a va2 s .c om * v {1, 2, 3} * |v| 3.74... * * @param v values of vector as arraylist. * @return magnitude */ public static double magnitudeVector(ArrayList<Double> v) { double vectorContent = 0; for (Double d : v) { vectorContent += Math.pow(d, 2); } return Math.sqrt(vectorContent); }
From source file:Main.java
public static String humanReadableCount(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); char pre = "KMGTPE".charAt(exp - 1); return String.format("%.2f %s" + (si ? "bps" : "B"), bytes / Math.pow(unit, exp), pre); }
From source file:Main.java
public static String humanReadableByteCount(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) { return bytes + " B"; }// www.j a v a2s . co m final int exp = (int) (Math.log(bytes) / Math.log(unit)); final String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); }
From source file:Main.java
public static double getScreenSize(Activity activity) { if (dm == null) { dm = new DisplayMetrics(); }// www . ja va2 s . c o m activity.getWindowManager().getDefaultDisplay().getMetrics(dm); double x = Math.pow(dm.widthPixels / dm.densityDpi, 2); double y = Math.pow(dm.heightPixels / dm.densityDpi, 2); return Math.sqrt(x + y); }