List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:Main.java
public static int computeMaxActiveApplicationsPerUser(int maxActiveApplications, int userLimit, float userLimitFactor) { return Math.max((int) Math.ceil(maxActiveApplications * (userLimit / 100.0f) * userLimitFactor), 1); }
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 {/*from w ww . ja 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 {/* w ww . ja va 2 s . c o m*/ int sampleSize = Math.min(w / minSideLength, h / minSideLength); return Math.max(sampleSize, lowerBound); } }
From source file:Main.java
/** * draw the image to viewBitmap in scale mode. * @param viewBitmap Bitmap to be displayed on the device. * @param bitmap Bitmap image./*w ww . ja va2 s . c o m*/ */ public static void drawImageForScalesMode(final Bitmap viewBitmap, final Bitmap bitmap) { float startGridX = 0; float startGridY = 0; float getSizeW = bitmap.getWidth(); float getSizeH = bitmap.getHeight(); float scale; final int width = viewBitmap.getWidth(); final int height = viewBitmap.getHeight(); if ((getSizeW / width) > (getSizeH / height)) { scale = width / getSizeW; } else { scale = height / getSizeH; } int targetW = (int) Math.ceil(scale * getSizeW); int targetH = (int) Math.ceil(scale * getSizeH); Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, targetW, targetH, false); if ((getSizeW / width) > (getSizeH / height)) { startGridY = (height / 2 - targetH / 2); } else { startGridX = (width / 2 - targetW / 2); } Canvas canvas = new Canvas(viewBitmap); canvas.drawBitmap(resizedBitmap, startGridX, startGridY, null); }
From source file:Main.java
public static int getMaxZoomLevel(int imageWidth, int imageHeight) { int biggerSize = imageWidth > imageHeight ? imageWidth : imageHeight; if (biggerSize == 0) { return 0; }/*from w w w. ja va2s . com*/ return (int) Math.ceil(Math.log((double) biggerSize) / Math.log(2.0)); }
From source file:Main.java
/** * @author chri//from w w w. j ava 2 s.c om */ public static String roundDecimalsToString(double d) { // using DecimalFormat we get i18n issues. if (d < 10) return String.valueOf(Math.ceil(d * 100) / 100); if (d < 100) return String.valueOf(Math.ceil(d * 10) / 10); else return String.valueOf(Math.round(d)); }
From source file:Main.java
public static int dp(float value) { if (value == 0) { return 0; }/*from w w w .ja va 2 s.c o m*/ return (int) Math.ceil(density * value); }
From source file:Main.java
/** * This function decodes a base 2 string into its corresponding byte array. * * @param base2 The base 2 encoded string. * @return The corresponding byte array. *//*from w w w .j av a 2 s .co m*/ static public byte[] decode(String base2) { String string = base2.replaceAll("\\s", ""); // remove all white space int length = string.length(); byte[] bytes = new byte[(int) Math.ceil(length / 8)]; for (int i = 0; i < bytes.length; i++) { int b = 0; for (int j = 0; j < 8; j++) { char character = string.charAt(i * 8 + j); int bit = lookupTable.indexOf(character); if (bit < 0) throw new NumberFormatException("Attempted to decode a string that is not base 2: " + string); b = (b << 1) | bit; } bytes[i] = (byte) b; } return bytes; }
From source file:com.mycompany.semconsolewebapp.FFT.java
public static int nextPower2(int length) { if (length == 0) { return 0; } else {/* ww w. j av a2 s.c o m*/ return 1 << (int) Math.ceil(Math.log(length) / Math.log(2)); } }
From source file:Main.java
/** * Returns the 'percentile' value in array * @param array A {@code double} array * @param percentile The percentile value to obtain between 0-1 * @return returns value at {@code percentile} in {@code array} * */// w w w .j a v a2 s . c o m public static double percentile(double[] array, double percentile) { Arrays.sort(array); if (array.length == 0 || percentile < 0 || percentile > 1) throw new IllegalArgumentException(); double k = (array.length - 1) * percentile; double f = Math.floor(k); double c = Math.ceil(k); if (f == c) return array[(int) k]; return array[(int) f] * (c - k) + array[(int) c] * (k - f); }