Example usage for java.lang Math abs

List of usage examples for java.lang Math abs

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double abs(double a) 

Source Link

Document

Returns the absolute value of a double value.

Usage

From source file:Main.java

public static int randomInRange(int min, int max) {
    return random.nextInt(Math.abs(max - min) + 1) + min;
}

From source file:Main.java

public static int calcyseal(int bthyear) {

    int abs = (Math.abs(1965 - bthyear));
    y = abs / 4.00;/*from  w ww.  j  a v a  2s .c  o  m*/
    y = y - Math.floor(y);
    if (y > 0) {
        cont = calcyseal(bthyear + 1);
        return (cont + 1);
    } else
        return (1);
}

From source file:Main.java

private static boolean isNewRatioInferior(double d, android.hardware.Camera.Size size,
        android.hardware.Camera.Size size1) {
    return Math.abs(d - (double) size.height / (double) size.width) <= Math
            .abs(d - (double) size1.height / (double) size1.width);
}

From source file:MathUtils.java

public static long ppcm(int a, int b) {
    return Math.abs(multiplyAndCheck(a / pgcd(a, b), b));
}

From source file:Main.java

public static int getTextBaseLine(Paint paint) {
    Paint.FontMetrics fm = paint.getFontMetrics();
    return (int) Math.abs(fm.bottom);
}

From source file:Main.java

public static int findValueClosestTo(int value, byte[] allowedValues) {
    int smallestDistance = Math.abs(allowedValues[0] - value);
    int index = 0;
    for (int i = 1; i < allowedValues.length; i++) {
        int currDistance = Math.abs(allowedValues[i] - value);
        if (currDistance < smallestDistance) {
            index = i;/*  ww  w. j  a  v a2  s .c  o m*/
            smallestDistance = currDistance;
        }
    }
    return allowedValues[index];
}

From source file:Main.java

public static synchronized String getNonce() {
    SecureRandom sr = new SecureRandom();
    return Long.toString(Math.abs(sr.nextLong()), Character.MAX_RADIX);
}

From source file:Main.java

public static int getMinutesBetweenTwoDates(Date start, Date end) {
    long diff = Math.abs(end.getTime() - start.getTime());
    return (int) (diff / 1000 / 60);
}

From source file:Main.java

public static int getDisplayWidthValue(int designWidthValue) {

    if (Math.abs(designWidthValue) < 2) {
        return designWidthValue;
    }/*w w  w  .j  ava  2s  .c  o  m*/

    return designWidthValue * displayWidth / designWidth;

}

From source file:Main.java

public static double getXMoveDistance(double slope, double dis) {
    if (slope == Double.MAX_VALUE) {
        return dis;
    }//from  w  w  w. j a va 2 s  .  c o  m
    return Math.abs((dis * slope) / Math.sqrt(1 + slope * slope));
}