List of usage examples for java.lang Math floor
public static double floor(double a)
From source file:Main.java
/** * Calculate the Geometric Mean Longitude of the Sun. * This value is close to 0 degree at the spring equinox, * 90 degree at the summer solstice, 180 degree at the automne equinox * and 270 degree at the winter solstice. * * @param t number of Julian centuries since J2000. * @return Geometric Mean Longitude of the Sun in degrees, * in the range 0 degree (inclusive) to 360 degree (exclusive). *///from w w w .j a v a 2s.c o m private static double sunGeometricMeanLongitude(final double t) { double L0 = 280.46646 + t * (36000.76983 + 0.0003032 * t); L0 = L0 - 360 * Math.floor(L0 / 360); return L0; }
From source file:StringUtil.java
/** * Takes a double and turns it into a percent string. * Ex. 0.5 turns into 50%/*w w w . j a v a 2 s. c om*/ * * @param value * @return corresponding percent string */ public static String getPercentValue(double value) { //moved from HTMLReport.getPercentValue() value = Math.floor(value * 100) / 100; //to represent 199 covered lines from 200 as 99% covered, not 100 % return NumberFormat.getPercentInstance().format(value); }
From source file:Main.java
/** * Loads given image asset, scaling the image down if it is too big to improve performance. * @param context Application context//from w w w .ja va 2 s . c o m * @param path Path in the assets folder of the image to load * @return Loaded image bitmap */ public static Bitmap loadImageFromAssets(Context context, String path) { try { // Open the input stream to the image in assets InputStream is = context.getAssets().open(path); // Load the image dimensions first so that big images can be scaled down (improves memory usage) BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options(); onlyBoundsOptions.inJustDecodeBounds = true; onlyBoundsOptions.inDither = true; BitmapFactory.decodeStream(is, null, onlyBoundsOptions); is.close(); if ((onlyBoundsOptions.outWidth == -1) || (onlyBoundsOptions.outHeight == -1)) { // There was an error while decoding return null; } // Find the bigger dimension (width, height) int originalSize = (onlyBoundsOptions.outHeight > onlyBoundsOptions.outWidth) ? onlyBoundsOptions.outHeight : onlyBoundsOptions.outWidth; // Calculate the sampling ratio for images that are bigger than the thumbnail size double ratio = (originalSize > THUMBNAIL_SIZE) ? (originalSize / THUMBNAIL_SIZE) : 1.0; int sampleSize = Integer.highestOneBit((int) Math.floor(ratio)); // Load the image sampled using the calculated ratio BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); bitmapOptions.inSampleSize = sampleSize; bitmapOptions.inDither = true; is = context.getAssets().open(path); Bitmap bitmap = BitmapFactory.decodeStream(is, null, bitmapOptions); is.close(); return bitmap; } catch (IOException e) { return null; } }
From source file:Main.java
private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { // return the larger one when there is no overlapping zone. return lowerBound; }/*from w w w . j a v a 2s . com*/ if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } }
From source file:com.caseystella.analytics.outlier.batch.rpca.AugmentedDickeyFuller.java
/** * Uses the Augmented Dickey Fuller test to determine * if ts is a stationary time series//from www.ja va 2 s . com * @param ts */ public AugmentedDickeyFuller(double[] ts) { this.ts = ts; this.lag = (int) Math.floor(Math.cbrt((ts.length - 1))); computeADFStatistics(); }
From source file:edu.mit.genecircuits.GcUtils.java
/** * Take a time in [ms] and convert it into [h min s ms]. * @param dt [ms]/*w w w. j a v a 2 s . c om*/ * @return Time [h m s ms] */ public static String chronometer(long dt) { int numHours = 0; int numMinutes = 0; int numSeconds = 0; //System.out.println(dt); numHours = (int) Math.floor(dt / 3600000.0); dt -= numHours * 3600000.0; numMinutes = (int) Math.floor(dt / 60000.0); dt -= numMinutes * 60000.0; numSeconds = (int) Math.floor(dt / 1000.0); dt -= numSeconds * 1000.0; String time = Integer.toString(numHours) + "h "; time += Integer.toString(numMinutes) + "min "; time += Integer.toString(numSeconds) + "s "; time += Integer.toString((int) dt) + "ms"; return time; }
From source file:change_point_detection.BetaDistributionChangePoint.java
public int/*estimated change point*/ detectChange() throws Exception { int estimatedChangePoint = -1; int N = this.dynamicWindow.size(); this.cushion = Math.max(100, (int) Math.floor(Math.pow(N, gamma))); //mean conf. should not fall below 0.3 if (N > (2 * this.cushion) && calculateMean(0, N - 1) <= 0.3) return N - 1; double threshold = -Math.log(this.sensitivity); double w = 0; int kAtMaxW = -1; for (int k = this.cushion; k <= N - this.cushion; k++) { if (calculateMean(k, N - 1) <= 0.95 * calculateMean(0, k - 1)) { double skn = 0; /* estimate pre and post change parameters */ double alphaPreChange = calcBetaDistAlpha(0, k - 1); double betaPreChange = calculateBetaDistBeta(alphaPreChange, 0, k - 1); double alphaPostChange = calcBetaDistAlpha(k, N - 1); double betaPostChange = calculateBetaDistBeta(alphaPostChange, k, N - 1); BetaDistributionImpl preBetaDist = new BetaDistributionImpl(alphaPreChange, betaPreChange); BetaDistributionImpl postBetaDist = new BetaDistributionImpl(alphaPostChange, betaPostChange); for (int i = k; i < N; i++) { try { skn += Math.log(postBetaDist.density(this.dynamicWindow.get(i).doubleValue()) / preBetaDist.density(this.dynamicWindow.get(i).doubleValue())); } catch (Exception e) { e.printStackTrace(); System.out.println("continuing..."); skn = 0;//w ww . j av a 2s . co m break; } } if (skn > w) { w = skn; kAtMaxW = k; } } } if (w >= threshold && kAtMaxW != -1) { System.out.println("\nChangePoint Found!"); estimatedChangePoint = kAtMaxW; System.out.println("Estimated change point is " + estimatedChangePoint); } //force change point if confidence falls down terribly if (estimatedChangePoint == -1 && N >= 100 && calculateMean(0, N - 1) < 0.3) estimatedChangePoint = N - 1; return estimatedChangePoint; }
From source file:com.esofthead.mycollab.core.utils.FileUtils.java
public static String getVolumeDisplay(Long volume) { long GB_SIZE = 1024 * 1024 * 1024; long MB_SIZE = 1024 * 1024; long KB_SIZE = 1024; if (volume == null) { return "0 Kb"; } else if (volume < KB_SIZE) { return volume + " Bytes"; } else if (volume < MB_SIZE) { return Math.floor(((float) volume / KB_SIZE) * 100) / 100 + " Kb"; } else if (volume < GB_SIZE) { return Math.floor(((float) volume / MB_SIZE) * 100) / 100 + " Mb"; } else {//from ww w .j a v a 2 s . com return Math.floor((volume / GB_SIZE) * 100) / 100 + " Gb"; } }
From source file:com.feilong.commons.core.util.RandomUtil.java
/** * 0-?.<br>// w ww . j a v a 2 s . co m * <b>??{@link #JVM_RANDOM}</b> * * @param number * ? * @return 0-? */ public static long createRandom(Number number) { // double random = Math.random(); double random = JVM_RANDOM.nextDouble(); return (long) Math.floor(random * number.longValue()); }
From source file:com.galenframework.specs.RangeValue.java
public int asInt() { if (value > 0) { return (int) Math.floor(value / Math.pow(10, precision)); } else {/*from w w w .java 2 s . co m*/ return (int) Math.ceil(value / Math.pow(10, precision)); } }