List of usage examples for java.lang Math log
@HotSpotIntrinsicCandidate public static double log(double a)
From source file:Main.java
public static String ReadableByteCount(long bytes) { int unit = 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = String.valueOf("KMGTPE".charAt(exp - 1)); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); }
From source file:Main.java
public static String formatBits(long bytes) { int unit = 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = ("KMGTPE").charAt(exp - 1) + ""; return String.format(Locale.ENGLISH, "%.1f %sb", bytes / Math.pow(unit, exp), pre); }
From source file:Main.java
public static BitmapFactory.Options createBitmapScaledOptions(int targetResolution, int actualResolution) { double scaleFactor = Math.log((double) actualResolution / (double) targetResolution) / Math.log(2); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = Math.max(1, (int) Math.floor(scaleFactor)); return options; }
From source file:Main.java
public static String formatBytes(long bytes) { int unit = 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = ("KMGTPE").charAt(exp - 1) + ""; return String.format(Locale.ENGLISH, "%.1f %sB", 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"; 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
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 calculateMinZoomLevel(int width, int height, int tileSize) { int max = Math.max(width, height); int tilesCount = (int) Math.ceil(1d * max / tileSize); return Math.ceil(Math.log(tilesCount) / Math.log(2d)); }
From source file:Main.java
public static String humanReadableByteCount(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) { return bytes + " B"; }//from w w w.ja va 2 s. c o 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 Bitmap createPOT(Bitmap bmp) { Bitmap potBmp = null;// www. j a v a2 s . c om 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
public static String getSigFig(double value, int n) { String result = String.format("%.10f", value); int k = (int) (Math.log(Math.abs(value)) / Math.log(10)); if ((k + 1) >= n) { // Assume value > 0 result = result.substring(0, n); } else {//from www. j av a 2 s. c o m if (value < 0) { n = n + 1; } if (0 < Math.abs(value) && Math.abs(value) < 1) { n = n + 1; } if (value != 0) { result = result.substring(0, n + 1); } else { n = n + 2; result = "0.0"; } // Add trailing zeros while (result.length() < n) { result = result + "0"; } } return result; }