List of usage examples for java.lang Math floor
public static double floor(double a)
From source file:Main.java
public static void end() { GregorianCalendar endtime = new GregorianCalendar(); long difference = endtime.getTimeInMillis() - starttime.getTimeInMillis(); int mins = (int) Math.floor(difference / 60000.0); double secs = (difference / 1000.0 - mins * 60.0); System.out.println(mins + " m " + secs + " s"); }
From source file:Main.java
public static Bitmap getSampledBitmap(String filePath, int reqWidth, int reqHeight) { Options options = new Options(); options.inJustDecodeBounds = true;/* ww w. ja va 2s. c om*/ BitmapFactory.decodeFile(filePath, options); // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { if (width > height) { inSampleSize = (int) Math.floor(((float) height / reqHeight) + 0.5f); // Math.round((float)height // / // (float)reqHeight); } else { inSampleSize = (int) Math.floor(((float) width / reqWidth) + 0.5f); // Math.round((float)width // / // (float)reqWidth); } } // System.out.println("inSampleSize--->"+inSampleSize); options.inSampleSize = inSampleSize; options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(filePath, options); }
From source file:Main.java
public static double translatePixelsToInches(double pixels) { double inches = pixels / 72.0; inches = (Math.floor(inches * 100.0)) / 100.0; return inches; }
From source file:Main.java
private static int roundTo(int in, int precision) { return precision * ((int) Math.floor(in / (1.0 * precision))); }
From source file:Main.java
public static void invalidateGlobalRegion(View view, RectF childBounds) { //childBounds.offset(view.getTranslationX(), view.getTranslationY()); if (DEBUG_INVALIDATE) Log.v(TAG, "-------------"); while (view.getParent() != null && view.getParent() instanceof View) { view = (View) view.getParent(); view.getMatrix().mapRect(childBounds); view.invalidate((int) Math.floor(childBounds.left), (int) Math.floor(childBounds.top), (int) Math.ceil(childBounds.right), (int) Math.ceil(childBounds.bottom)); if (DEBUG_INVALIDATE) { Log.v(TAG,/*from w ww.j a v a 2s .c o m*/ "INVALIDATE(" + (int) Math.floor(childBounds.left) + "," + (int) Math.floor(childBounds.top) + "," + (int) Math.ceil(childBounds.right) + "," + (int) Math.ceil(childBounds.bottom)); } } }
From source file:Main.java
private static int getDoubleChars(double number, char[] buf, int charPos, int significantDigits) { if (number != number) { STR_NAN.getChars(0, STR_NAN_LEN, buf, charPos); return charPos + STR_NAN_LEN; }//from ww w . ja va 2 s . c om //we need to detect -0.0 to be compatible with JDK boolean negative = (Double.doubleToRawLongBits(number) & 0x8000000000000000L) != 0; if (negative) { buf[charPos++] = '-'; number = -number; } if (number == Double.POSITIVE_INFINITY) { STR_INFINITY.getChars(0, STR_INFINITY_LEN, buf, charPos); return charPos + STR_INFINITY_LEN; } if (number == 0) { buf[charPos++] = '0'; buf[charPos++] = '.'; buf[charPos++] = '0'; } else { int exponent = 0; // calc. the power (base 10) for the given number: int pow = (int) Math.floor(Math.log(number) / LN10); // use exponential formatting if number too big or too small if (pow < -3 || pow > 6) { exponent = pow; number /= Math.exp(LN10 * exponent); } // if // Recalc. the pow if exponent removed and d has changed pow = (int) Math.floor(Math.log(number) / LN10); // Decide how many insignificant zeros there will be in the // lead of the number. int insignificantDigits = -Math.min(0, pow); // Force it to start with at least "0." if necessarry pow = Math.max(0, pow); double divisor = Math.pow(10, pow); // Loop over the significant digits (17 for double, 8 for float) for (int i = 0, end = significantDigits + insignificantDigits, div; i < end; i++) { // Add the '.' when passing from 10^0 to 10^-1 if (pow == -1) { buf[charPos++] = '.'; } // if // Find the divisor div = (int) (number / divisor); // This might happen with 1e6: pow = 5 ( instead of 6 ) if (div == 10) { buf[charPos++] = '1'; buf[charPos++] = '0'; } // if else { buf[charPos] = (char) (div + '0'); charPos++; } // else number -= div * divisor; divisor /= 10.0; pow--; // Break the loop if we have passed the '.' if (number == 0 && divisor < 0.1) break; } // for // Remove trailing zeros while (buf[charPos - 1] == '0') charPos--; // Avoid "4." instead of "4.0" if (buf[charPos - 1] == '.') charPos++; if (exponent != 0) { buf[charPos++] = 'E'; if (exponent < 0) { buf[charPos++] = '-'; exponent = -exponent; } if (exponent >= 100) buf[charPos++] = (char) (exponent / 100 + '0'); if (exponent >= 10) buf[charPos++] = (char) (exponent / 10 % 10 + '0'); buf[charPos++] = (char) (exponent % 10 + '0'); } // if } return charPos; }
From source file:com.galenframework.specs.RangeValue.java
private static int convertValue(double value, int precision) { if (value > 0) { return (int) Math.floor(value * Math.pow(10, precision)); } else {// w w w .jav a2 s .c o m return (int) Math.ceil(value * Math.pow(10, precision)); } }
From source file:Main.java
public static String formatCoordinate(double coordinate, int outputType) { StringBuilder sb = new StringBuilder(); char endChar = DEGREE_CHAR; DecimalFormat df = new DecimalFormat("###.####"); if (outputType == Location.FORMAT_MINUTES || outputType == Location.FORMAT_SECONDS) { df = new DecimalFormat("##.###"); int degrees = (int) Math.floor(coordinate); sb.append(degrees);/*from w ww .j a v a 2s .c o m*/ sb.append(DEGREE_CHAR); // degrees sign endChar = '\''; // minutes sign coordinate -= degrees; coordinate *= 60.0; if (outputType == Location.FORMAT_SECONDS) { df = new DecimalFormat("##.##"); int minutes = (int) Math.floor(coordinate); sb.append(minutes); sb.append('\''); // minutes sign endChar = '\"'; // seconds sign coordinate -= minutes; coordinate *= 60.0; } } sb.append(df.format(coordinate)); sb.append(endChar); return sb.toString(); }
From source file:Main.java
private static void initialize(int size) { greatestFactor = new int[size]; // wheel factorization (sort of...) greatestFactor[1] = 1;/*from w w w. j a va2 s .c om*/ for (Integer seed : seeds) { for (int i = seed; i < size; i += seed) { greatestFactor[i] = seed; } } // now do modified Sieve of Er... int sqrt = (int) Math.floor(Math.sqrt(size) + 1); for (int prime = 2; prime < sqrt; prime++) { if (0 == greatestFactor[prime]) { for (int i = prime; i < size; i += prime) { greatestFactor[i] = prime; } } } // now flesh out the rest of the sieve. for (int i = sqrt; i < size; i++) { if (0 == greatestFactor[i]) { greatestFactor[i] = i; } } }
From source file:Main.java
public static BufferedImage create(BufferedImage image, double angle, GraphicsConfiguration gc) { double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle)); int w = image.getWidth(), h = image.getHeight(); int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin); int transparency = image.getColorModel().getTransparency(); BufferedImage result = gc.createCompatibleImage(neww, newh, transparency); Graphics2D g = result.createGraphics(); g.translate((neww - w) / 2, (newh - h) / 2); g.rotate(angle, w / 2, h / 2);/*from w ww . j a v a 2 s.c om*/ g.drawRenderedImage(image, null); return result; }