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

private static float getCurvature(final float dxt, final float dyt, final float ddxt, final float ddyt) {
    return Math.abs(dxt * ddyt - dyt * ddxt) / (float) Math.pow(dxt * dxt + dyt * dyt, 3f / 2f);
}

From source file:Main.java

public static double getPreviewAspectRatio(int width, int height) {
    double ratio = 0.0f;
    if (Math.abs((double) width / height - 4.0 / 3.0) > Math.abs((double) width / height - 16.0 / 9.0)) {
        ratio = 16.0f / 9.0f;/*w  w  w .ja v  a  2 s  . com*/
    } else {
        ratio = 4.0f / 3.0f;
    }
    return ratio;
}

From source file:Main.java

public static int getRandInt() {
    return Math.abs(rd.nextInt());
}

From source file:Main.java

public static float getViewY(View view) {
    return Math.abs((view.getBottom() - view.getTop()) / 2);
}

From source file:Main.java

public static float getViewX(View view) {
    return Math.abs((view.getRight() - view.getLeft()) / 2);
}

From source file:Main.java

private static int findClosest(int[] paramArrayOfInt, int paramInt) {
    int i = 0;//from   ww  w.j  av  a  2s. c o  m
    int j = Math.abs(paramArrayOfInt[0] - paramInt);
    int k = 1;
    while (true) {
        int m = paramArrayOfInt.length;
        if (k >= m)
            break;
        int n = Math.abs(paramArrayOfInt[k] - paramInt);
        if (n < j) {
            j = n;
            i = k;
        }
        k += 1;
    }
    return i;
}

From source file:Main.java

public static boolean isEpsilonEquals(float first, float second) {
    return (Math.abs(first - second) < epsilon);
}

From source file:Main.java

public static boolean closeMatch(int color1, int color2, int tolerance) {
    if (Math.abs(Color.red(color1) - Color.red(color2)) > tolerance)
        return false;
    if (Math.abs(Color.green(color1) - Color.green(color2)) > tolerance)
        return false;
    if (Math.abs(Color.blue(color1) - Color.blue(color2)) > tolerance)
        return false;
    return true;/*from ww w.j av  a 2s  . com*/
}

From source file:Maths.java

/** sqrt(a^2 + b^2) without under/overflow. **/

public static double hypot(double a, double b) {
    double r;/*w  ww .j  a v  a 2 s  . c om*/
    if (Math.abs(a) > Math.abs(b)) {
        r = b / a;
        r = Math.abs(a) * Math.sqrt(1 + r * r);
    } else if (b != 0) {
        r = a / b;
        r = Math.abs(b) * Math.sqrt(1 + r * r);
    } else {
        r = 0.0;
    }
    return r;
}

From source file:Main.java

public static boolean compareColorArea(Bitmap userFinalBitmap, Bitmap colored, int w, int h) {
    if (Math.abs(userFinalBitmap.getPixel(w, h) - (colored.getPixel(w, h))) <= 100) {
        return true;
    }// www .  jav a2  s. c o  m
    return false;
}