Example usage for java.lang Math floor

List of usage examples for java.lang Math floor

Introduction

In this page you can find the example usage for java.lang Math floor.

Prototype

public static double floor(double a) 

Source Link

Document

Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:Main.java

public static <T> T random(T[] array) {
    return array[(int) Math.floor(Math.random() * array.length)];
}

From source file:Main.java

/**
 * @see <a href="http://svn.xiph.org/trunk/vorbis/lib/sharedbook.c">_book_maptype1_quantvals</a>
 *//*from   ww  w .j a  va2s .co  m*/
private static long mapType1QuantValues(long entries, long dimension) {
    return (long) Math.floor(Math.pow(entries, 1.d / dimension));
}

From source file:Main.java

public static int colorBurn(int RGBValues) {
    int red = RGBValues >> 16 & 0xFF;
    int green = RGBValues >> 8 & 0xFF;
    int blue = RGBValues & 0xFF;
    red = (int) Math.floor(red * (1 - 0.1));
    green = (int) Math.floor(green * (1 - 0.1));
    blue = (int) Math.floor(blue * (1 - 0.1));
    return Color.rgb(red, green, blue);
}

From source file:Main.java

public static String generateNickname() {
    Random rnd = new Random(System.currentTimeMillis());
    int race_selection = rnd.nextInt(3);

    String thefirstname = "";
    String thelastname = "";
    String thefirstname1 = "";
    String thelastname1 = "";

    if (race_selection == 0) {
        double fnprefix1 = Math.floor(Math.random() * 122);
        double fnsuffix1 = Math.floor(Math.random() * 91);
        double lnprefix1 = Math.floor(Math.random() * 67);
        double lnsuffix1 = Math.floor(Math.random() * 64);

        thefirstname = h_fnpre.get((int) fnprefix1) + h_fnsuf.get((int) fnsuffix1);
        thelastname = h_lnpre.get((int) lnprefix1) + h_lnsuf.get((int) lnsuffix1);

        thefirstname1 = thefirstname.substring(0, 1).toUpperCase();
        thefirstname = thefirstname1 + thefirstname.substring(1, thefirstname.length());

        thelastname1 = thelastname.substring(0, 1).toUpperCase();
        thelastname = thelastname1 + thelastname.substring(1, thelastname.length());

    } else if (race_selection == 0) {
        double fnprefix1 = Math.floor(Math.random() * 80);
        double fnsuffix1 = Math.floor(Math.random() * 67);

        thefirstname = o_fnpre.get((int) fnprefix1) + o_fnsuf.get((int) fnsuffix1);
        thelastname = "";

    } else {/*from  w  w w .  ja  va2s. com*/
        double fnprefix1 = Math.floor(Math.random() * 122);
        double fnsuffix1 = Math.floor(Math.random() * 91);

        thefirstname = h_fnpre.get((int) fnprefix1) + h_fnsuf.get((int) fnsuffix1);

    }

    return thefirstname + " " + thelastname;
}

From source file:Main.java

/**
 * Given a number, round up to the nearest power of ten times 1, 2, or 5.
 * /*from   w  w  w  .  java 2  s  . c  om*/
 * @param val the number, it must be strictly positive
 */
private static double roundUp(final double val) {
    int exponent = (int) Math.floor(Math.log10(val));
    double rval = val * Math.pow(10, -exponent);
    if (rval > 5.0) {
        rval = 10.0;
    } else if (rval > 2.0) {
        rval = 5.0;
    } else if (rval > 1.0) {
        rval = 2.0;
    }
    rval *= Math.pow(10, exponent);
    return rval;
}

From source file:Main.java

public static RectF floor(final RectF rect) {
    rect.left = (float) Math.floor(rect.left);
    rect.top = (float) Math.floor(rect.top);
    rect.right = (float) Math.floor(rect.right);
    rect.bottom = (float) Math.floor(rect.bottom);
    return rect;//from www.j a  va  2 s.com
}

From source file:Main.java

public static <T> List<List<T>> partition(List<T> items, int slices) {
    double size = items.size() / (double) slices;
    double accum = 0;
    int start = 0;
    List<List<T>> list = new ArrayList<>(slices);
    for (int i = 0; i < slices; i++) {
        int end = (int) Math.floor(accum + size);
        if (i == slices - 1)
            end = items.size();/*from   w  w w  .  j av a 2 s .  c o m*/
        list.add(items.subList(start, end));
        accum += size;
        start = (int) Math.floor(accum);
    }
    return list;
}

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  2  s  .  c om
    if ((maxNumOfPixels == -1) && (minSideLength == -1)) {
        return 1;
    } else if (minSideLength == -1) {
        return lowerBound;
    } else {
        return upperBound;
    }
}

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) ? 1280
            : (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 ww w  .j av a2s. co m*/

    if ((maxNumOfPixels == -1) && (minSideLength == -1)) {
        return 1;
    } else if (minSideLength == -1) {
        return lowerBound;
    } else {
        return upperBound;
    }
}

From source file:Main.java

public static void centerWindow(Window window, int width, int height) {
    // Get screen size
    final Toolkit tk = Toolkit.getDefaultToolkit();
    final Dimension screensize = tk.getScreenSize();

    // Set window minimum size
    window.setMinimumSize(new Dimension((int) Math.floor(screensize.getWidth() * 0.3),
            (int) Math.floor(screensize.getHeight() * 0.3)));

    // Set window size
    if (width == 0f)
        width = (int) Math.floor(screensize.getWidth() * 0.8);

    if (height == 0f)
        height = (int) Math.floor(screensize.getHeight() * 0.8);

    window.setPreferredSize(new Dimension(width, height));

    int left = (int) (screensize.getWidth() - width) / 2;
    int right = (int) (screensize.getHeight() - height) / 2;
    ;/*from  w  w  w . j  ava2  s.  c o m*/

    // Center window
    window.setLocation(left, right);
}