List of usage examples for java.lang Math floor
public static double floor(double a)
From source file:Main.java
/** * Take a universal time between 0 and 24 and return a triple * [hours, minutes, seconds].// w w w. j a v a2 s. co m * * @param ut Universal time - presumed to be between 0 and 24. * @return [hours, minutes, seconds] */ public static int[] clockTimeFromHrs(double ut) { int[] hms = new int[3]; hms[0] = (int) Math.floor(ut); double remainderMins = 60 * (ut - hms[0]); hms[1] = (int) Math.floor(remainderMins); hms[2] = (int) Math.floor(remainderMins - hms[1]); return hms; }
From source file:Main.java
/** * <p>// w w w . ja v a2 s .c o m * getCenter. * </p> * * @param component * a {@link java.awt.Component} object. * @return a {@link java.awt.Point} object. */ public static Point getCenter(final Component component) { final Point point = component.getLocation(); point.translate( // (int) Math.floor((component.getWidth() + 0.5) / 2.0), // (int) Math.floor((component.getHeight() + 0.5) / 2.0)); return point; }
From source file:Main.java
private static int[] hsvToRgb(double h, double s, double v) { double r = 0, g = 0, b = 0; double i = (int) Math.floor(h * 6); double f = h * 6 - i; double p = v * (1 - s); double q = v * (1 - f * s); double t = v * (1 - (1 - f) * s); switch ((int) i % 6) { case 0:/* www . j av a 2s. c o m*/ r = v; g = t; b = p; break; case 1: r = q; g = v; b = p; break; case 2: r = p; g = v; b = t; break; case 3: r = p; g = q; b = v; break; case 4: r = t; g = p; b = v; break; case 5: r = v; g = p; b = q; break; } return new int[] { (int) (r * 255), (int) (g * 255), (int) (b * 255) }; }
From source file:Main.java
static String formatLatLon(double latLon, char positiveDirection, char negativeDirection) { boolean isPositive = (latLon >= 0.0); double absLatLon = Math.abs(latLon); if (absLatLon > 180.0) { return "?"; }/* w ww . ja va 2s . c o m*/ double degrees = Math.floor(absLatLon); double degreeRemainder = absLatLon - degrees; double minutesAndSeconds = 60.0 * degreeRemainder; double minutes = Math.floor(minutesAndSeconds); double minuteRemainder = minutesAndSeconds - minutes; double seconds = 60.0 * minuteRemainder; return String.format(Locale.US, "%.0f\u00b0 %.0f\' %.3f\" %c", degrees, minutes, seconds, isPositive ? positiveDirection : negativeDirection); }
From source file:Main.java
public static double parseNmeaFormat(String degrees, String direction) { double latlong = 0.0; double temp1 = Double.parseDouble(degrees); double temp2 = Math.floor(temp1 / 100); double temp3 = (temp1 / 100 - temp2) / 0.6; if (DIRECTION_SOUTH.equals(direction) || DIRECTION_WEST.equals(direction)) { latlong = -(temp2 + temp3);// w ww . j a v a2s.c o m } else if (DIRECTION_NORTH.equals(direction) || DIRECTION_EAST.equals(direction)) { latlong = (temp2 + temp3); } return latlong; }
From source file:Main.java
public static int getFibonacciSeq(long f) { return (int) Math.floor(Math.log(f * sqrt(5) + 0.5) / Math.log(GOLDEN_RATIO)); }
From source file:Main.java
public static int randomInt(int upto) { int number;//ww w.j ava 2s . co m number = (int) Math.floor(Math.random() * upto); return number; }
From source file:Main.java
/** * Build an set.//from ww w . j a v a 2s. c om * * @param values * Values to be added in a set. * @return A set containing all given values. */ @SafeVarargs public static <T> Set<T> asSet(T... values) { if (values == null || values.length == 0) { return Collections.emptySet(); } else { // A lit bit higher than load factor int size = (int) Math.floor(values.length * 1.4); Set<T> set = new HashSet<>(size); for (T value : values) { set.add(value); } return set; } }
From source file:Main.java
public static String doubleToString(double value) { return Double.toString(Math.floor(value * 10000.0 + 0.5) / 10000.0); }
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 ww . j a v a 2s.com if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } }