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 readableFileSize(long size) { if (size <= 0) return "0KB"; final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; }
From source file:Main.java
public static String getReadableSize(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 getDistance(double longitude1, double latitude1, double longitude2, double latitude2) { double Lat1 = rad(latitude1); double Lat2 = rad(latitude2); double a = Lat1 - Lat2; double b = rad(longitude1) - rad(longitude2); double s = 2 * Math.asin(Math.sqrt( Math.pow(Math.sin(a / 2), 2) + Math.cos(Lat1) * Math.cos(Lat2) * Math.pow(Math.sin(b / 2), 2))); s = s * EARTH_RADIUS;/*from ww w .j av a 2s . c o m*/ s = Math.round(s * 10000) / 10000; return s; }
From source file:Main.java
public static String formatValue(double value) { if (value > 0) { int power; String suffix = " kmbt"; String formattedNumber = ""; NumberFormat formatter = new DecimalFormat("#,###.#"); power = (int) StrictMath.log10(value); value = value / (Math.pow(10, (power / 3) * 3)); formattedNumber = formatter.format(value); formattedNumber = formattedNumber + suffix.charAt(power / 3); return formattedNumber.length() > 4 ? formattedNumber.replaceAll("\\.[0-9]+", "") : formattedNumber; } else {/*w ww.j a v a 2s .com*/ return "0"; } }
From source file:Main.java
public static double round(double amount, int i) { double d = Math.pow(10.0D, i); return (Math.round(amount * d) / d); }
From source file:Main.java
/** * Rounds the given number to the given number of significant digits. Based on an answer on <a * href="http://stackoverflow.com/questions/202302">Stack Overflow</a>. *//*from w ww .j a va 2 s .c om*/ public static float roundToOneSignificantFigure(double num) { final float d = (float) Math.ceil((float) Math.log10(num < 0 ? -num : num)); final int power = 1 - (int) d; final float magnitude = (float) Math.pow(10, power); final long shifted = Math.round(num * magnitude); return shifted / magnitude; }
From source file:Main.java
public static List<Integer> getBitsFromIntagerNumber(Integer num) { String binary = Integer.toBinaryString(num); List<Integer> list = new ArrayList<Integer>(0); if (num == 0) list.add(num);//from www .j a v a 2 s . c o m for (int i = 0; i < binary.length(); i++) { if ((int) binary.charAt(i) == 49) list.add((int) Math.pow(2, binary.length() - 1 - i)); } return list; }
From source file:Main.java
/** * Calculates the constrast between two colors, using the algorithm provided by the WCAG v2. *//*from w ww .java2s .c o m*/ public static float computeContrastBetweenColors(int bg, int fg) { float bgR = Color.red(bg) / 255f; float bgG = Color.green(bg) / 255f; float bgB = Color.blue(bg) / 255f; bgR = (bgR < 0.03928f) ? bgR / 12.92f : (float) Math.pow((bgR + 0.055f) / 1.055f, 2.4f); bgG = (bgG < 0.03928f) ? bgG / 12.92f : (float) Math.pow((bgG + 0.055f) / 1.055f, 2.4f); bgB = (bgB < 0.03928f) ? bgB / 12.92f : (float) Math.pow((bgB + 0.055f) / 1.055f, 2.4f); float bgL = 0.2126f * bgR + 0.7152f * bgG + 0.0722f * bgB; float fgR = Color.red(fg) / 255f; float fgG = Color.green(fg) / 255f; float fgB = Color.blue(fg) / 255f; fgR = (fgR < 0.03928f) ? fgR / 12.92f : (float) Math.pow((fgR + 0.055f) / 1.055f, 2.4f); fgG = (fgG < 0.03928f) ? fgG / 12.92f : (float) Math.pow((fgG + 0.055f) / 1.055f, 2.4f); fgB = (fgB < 0.03928f) ? fgB / 12.92f : (float) Math.pow((fgB + 0.055f) / 1.055f, 2.4f); float fgL = 0.2126f * fgR + 0.7152f * fgG + 0.0722f * fgB; return Math.abs((fgL + 0.05f) / (bgL + 0.05f)); }
From source file:Main.java
public static double getDevicePhysicalSize(Context context) { int[] size = getRealScreenSize(context); DisplayMetrics dm = context.getResources().getDisplayMetrics(); double x = Math.pow(size[0] / dm.xdpi, 2); double y = Math.pow(size[1] / dm.ydpi, 2); return Math.sqrt(x + y); }
From source file:Main.java
public static double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) { double radLat1 = (lat_a * Math.PI / 180.0); double radLat2 = (lat_b * Math.PI / 180.0); double a = radLat1 - radLat2; double b = (lng_a - lng_b) * Math.PI / 180.0; 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;/* w w w . j a va2 s.c om*/ s = Math.round(s * 10000) / 10000; return s; }