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 int getAbilityModifier(int abilityScore) {
    double BASE = 10;

    double calculatedValue = (abilityScore - BASE) / 2;

    //Force round down is necessary for negative numbers.
    return (int) Math.floor(calculatedValue);
}

From source file:Main.java

public static Bitmap crop(Bitmap srcBmp, View canvasView, int downsampling) {
    float scale = 1f / downsampling;
    return Bitmap.createBitmap(srcBmp, (int) Math.floor((canvasView.getX()) * scale),
            (int) Math.floor((canvasView.getY()) * scale), (int) Math.floor((canvasView.getWidth()) * scale),
            (int) Math.floor((canvasView.getHeight()) * scale));
}

From source file:Main.java

public static Area getArrowFromTo(Point2D.Double from, Point2D.Double to) {
    double dx = 8;
    double dy = Math.floor(dx / 2);
    if (from.getX() < to.getX())
        dx *= -1;//  w ww .  java2  s .  c o m

    GeneralPath arrowHeadFrom = new GeneralPath();
    arrowHeadFrom.moveTo(to.getX() + dx, to.getY() - dy);
    arrowHeadFrom.lineTo(to.getX(), to.getY());
    arrowHeadFrom.lineTo(to.getX() + dx, to.getY() + dy);
    arrowHeadFrom.lineTo(to.getX() + dx, to.getY() + 0.1);
    arrowHeadFrom.lineTo(from.getX(), from.getY() + 0.1);
    arrowHeadFrom.lineTo(from.getX(), from.getY() - 0.1);
    arrowHeadFrom.lineTo(to.getX() + dx, to.getY() - 0.1);
    arrowHeadFrom.lineTo(to.getX() + dx, to.getY() - dy);

    Area b = new Area(arrowHeadFrom);

    return b;
}

From source file:Main.java

public static int colorBurn(int RGBValues) {
    int alpha = RGBValues >> 24;
    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

private static int normalizeDouble(double f) {
    double f2 = Math.max(0.0, Math.min(1.0, f));
    return (int) Math.floor(f2 == 1.0 ? COLOR_FLOAT_TO_INT_FACTOR : f2 * (COLOR_FLOAT_TO_INT_FACTOR + 1));
}

From source file:Main.java

/**
 * Performs a division and rounds downwards to the next integer.
 *
 * @param numerator   the numerator.//from   w w  w.  ja v  a2s  .co  m
 * @param denominator the denominator.
 * @return an integer value.
 */
public static int divideToFloor(int numerator, int denominator) {
    Double result = Math.floor((double) numerator / denominator);

    return result.intValue();
}

From source file:Main.java

public static String transferTP(String oldValue) {
    String newValue = oldValue;//from ww w  .j a  v  a 2  s . c om
    float ov = Float.valueOf(oldValue) / 1000;
    Formatter fmt = new Formatter();

    if (ov >= 100) {
        newValue = String.valueOf(Math.floor(ov + 0.5));
    } else if (ov > 10) {
        newValue = fmt.format("%.1f", ov).toString();
    } else {
        newValue = fmt.format("%.2f", ov).toString();
    }

    return newValue;
}

From source file:Main.java

public static RectF round(final RectF rect, final float share) {
    rect.left = (float) Math.floor(rect.left * share) / share;
    rect.top = (float) Math.floor(rect.top * share) / share;
    rect.right = (float) Math.floor(rect.right * share) / share;
    rect.bottom = (float) Math.floor(rect.bottom * share) / share;
    return rect;//  www  . j a v  a2  s .  c  o m
}

From source file:Main.java

public static long getFibonacciFast(int n) {
    return (long) Math.floor(pow(GOLDEN_RATIO, n) / sqrt(5) + 0.5);
}

From source file:Main.java

public static BitmapFactory.Options createBitmapScaledOptions(int targetResolution, int actualResolution) {
    double scaleFactor = Math.log((double) actualResolution / (double) targetResolution) / Math.log(2);

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = Math.max(1, (int) Math.floor(scaleFactor));

    return options;
}