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 double absSquareSum(double[] input) {
    double sum = 0;
    for (int i = 0; i < input.length; i++) {
        sum += Math.pow(Math.abs(input[i]), 2);
    }/*from w  ww  .  j  a  v a  2 s  .  com*/
    return sum;
}

From source file:Main.java

private static boolean isSimilar(int rgb1, int rgb2) {
    boolean res = Math.abs(rgb2 - rgb1) < SIMILAR;
    return res;//from   w w  w  .  j  a  va 2s.  c  o  m
}

From source file:Main.java

public static int getDisplayHeightValue(int designHeightValue) {

    if (Math.abs(designHeightValue) < 2) {
        return designHeightValue;
    }//from  ww w  .ja  v a 2 s. c om

    return designHeightValue * displayHeight / designHeight;

}

From source file:Main.java

public static boolean compareFloats(float f1, float f2) {
    return Math.abs(f1 - f2) <= EPSILON;
}

From source file:Main.java

private static String getSubdirectory(String resourceId) {
    return TextUtils.isEmpty(resourceId) ? resourceId : String.valueOf(Math.abs(resourceId.hashCode() % 100));
}

From source file:Main.java

public final static boolean epsilonEq(float f1, float f2) {
    return Math.abs(f1 - f2) < EPSILON;
}

From source file:Main.java

public static double calDistance(double latX, double lngX, double latY, double lngY) {
    double scale = 6400 * 1000 * (Math.PI / 180);
    double dX = scale * Math.abs((latX - latY));
    double dY = scale * Math.abs((lngX - lngY));
    return Math.sqrt(dX * dX + dY * dY);
}

From source file:Main.java

public static boolean isPrime(int number) {
    if (number == 1)
        return false;

    if (Math.abs(number) == 2)
        return true;

    if (number % 2 == 0)
        return false;

    for (int i = 3; i * i <= number; i += 2) {
        if (number % i == 0)
            return false;
    }// w  w w  . ja v a2s .c  om
    return true;
}

From source file:Main.java

public static int getRandom() {
    Random ran = new Random(System.currentTimeMillis());
    int ret = ran.nextInt();
    ret = Math.abs(ret);
    return ret;//  ww w . java2 s .co  m
}

From source file:Main.java

private static boolean equalRate(Camera.Size s, float rate) {
    float r = (float) (s.width) / (float) (s.height);
    if (Math.abs(r - rate) <= 0.03) {
        return true;
    } else {//from w w w  .j ava2  s . c  o m
        return false;
    }
}