List of usage examples for java.lang Math log
@HotSpotIntrinsicCandidate public static double log(double a)
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 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 double logSumExp(double a, double b) { double x = (a < b) ? a : b; double y = (a < b) ? b : a; if (y - x > 50) { return y; } else {//from w w w . ja va 2 s. c om return x + Math.log(1.0 + Math.exp(y - x)); } }
From source file:Main.java
@SuppressLint("DefaultLocale") public static String formatByteString(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 int latitudeToPixelY(double latitude, double zoomLevel, int tileSize) { double sinLatitude = Math.sin(latitude * (Math.PI / 180)); int mapSize = getMapSize(zoomLevel, tileSize); return (int) Math .round((0.5d - Math.log((1d + sinLatitude) / (1d - sinLatitude)) / (4d * Math.PI)) * mapSize); }
From source file:Main.java
public static String getHumanReadableByteCount(final long bytes, final boolean si) { final int unit = si ? 1000 : 1024; if (bytes < unit) { return bytes + " B"; } else {/*from w ww . j a v a 2 s. c om*/ 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 int scalePow2(int height, int width) { int scale = 1; int size = Math.max(height, width); if (size > IMAGE_MAX_SIZE) { scale = (int) Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) size) / Math.log(0.5))); }/*from www .java 2s . c o m*/ return scale; }
From source file:Main.java
public static double[] complexMagnitude(double[] complexInput) { double[] magnitude = new double[complexInput.length / 2]; for (int i = 0; i < complexInput.length / 2; i++) { double re = complexInput[2 * i]; double im = complexInput[2 * i + 1]; magnitude[i] = Math.log(re * re + im * im + 0.001); }/* ww w. j a v a 2 s .com*/ return magnitude; }
From source file:Main.java
public static int[] getMapTileFromCoordinates(final double aLat, final double aLon, final int zoom) { final int[] out = new int[2]; final double E2 = (double) aLat * Math.PI / 180; final long sradiusa = 6378137; final long sradiusb = 6356752; final double J2 = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa; final double M2 = (double) Math.log((1 + Math.sin(E2)) / (1 - Math.sin(E2))) / 2 - J2 * Math.log((1 + J2 * Math.sin(E2)) / (1 - J2 * Math.sin(E2))) / 2; final double B2 = (double) (1 << zoom); out[0] = (int) Math.floor(B2 / 2 - M2 * B2 / 2 / Math.PI); out[1] = (int) Math.floor((aLon + 180) / 360 * (1 << zoom)); return out;//w w w . j a v a 2 s . co m }
From source file:Main.java
public static double[] geoToMercator(double[] g) { double d = g[0] * Math.PI / 180, m = g[1] * Math.PI / 180, l = 6378137, k = 0.0818191908426, f = k * Math.sin(m);/* w w w . j a v a2s .c o m*/ double h = Math.tan(Math.PI / 4 + m / 2), j = Math.pow(Math.tan(Math.PI / 4 + Math.asin(f) / 2), k), i = h / j; // return new DoublePoint(Math.round(l * d), Math.round(l * // Math.log(i))); return new double[] { l * d, l * Math.log(i) }; }