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 intDivideRoundUp(int num, int divisor) {
    int sign = (num > 0 ? 1 : -1) * (divisor > 0 ? 1 : -1);
    return sign * (Math.abs(num) + Math.abs(divisor) - 1) / Math.abs(divisor);
}

From source file:Main.java

public static int getInsoleAngle(int axisX, int axisY, int axisZ) {
    int etalon = 4300;
    if (axisZ < 0) {
        return -1;
    }/*from  w w  w  . ja  v a  2 s.  co m*/

    axisX = Math.abs(axisX);
    axisY = Math.abs(axisY);
    axisZ = Math.abs(axisZ);

    int maxAxis = Math.max(axisY, axisX);

    double maxAngle = ((double) ((axisZ - maxAxis) * 100)) / etalon;

    return (int) (90 - maxAngle) / 2;
}

From source file:Main.java

public static String generateHashWhereClause(double lat, double lng) {
    double latHash = (lat + 180) / LATLON_SECTION;
    double lngHash = (lng + 180) / LATLON_SECTION;
    int latHashRounded = (int) Math.round(latHash);
    int lngHashRounded = (int) Math.round(lngHash);

    int iHash = getHash(latHashRounded, lngHashRounded);
    String whereClause = "hash = " + iHash;

    int nearbyLat = 0;
    int nearbyLng = 0;
    double overlap = LATLON_SECTION_EDGE;
    if (Math.abs(latHash - latHashRounded) > (0.5 - overlap))
        nearbyLat = (int) Math.signum(latHash - latHashRounded);

    if (Math.abs(lngHash - lngHashRounded) > (0.5 - overlap))
        nearbyLng = (int) Math.signum(lngHash - lngHashRounded);

    if (nearbyLat != 0)
        whereClause += " OR hash = " + getHash(latHashRounded + nearbyLat, lngHashRounded);
    if (nearbyLng != 0)
        whereClause += " OR hash = " + getHash(latHashRounded, lngHashRounded + nearbyLng);
    if ((nearbyLat != 0) && (nearbyLng != 0))
        whereClause += " OR hash = " + getHash(latHashRounded + nearbyLat, lngHashRounded + nearbyLng);

    Log.d(TAG,//from  ww  w.  j  ava2 s .c o  m
            "HotspotDbHelper generateHashWhereClause lat: " + lat + " lon: " + lng + " Where: " + whereClause);
    return whereClause;
}

From source file:dtu.ds.warnme.utils.RandomUtils.java

public static boolean compareDouble(double a, double b, int precision) {
    return Math.abs(a - b) <= Math.pow(10, -precision);
}

From source file:Main.java

public static float distance(float value1, float value2) {
    return Math.abs(value1 - value2);
}

From source file:Main.java

/**
 * calcs the optimal dimension for the camera preview on the display
 * /*from w w w.j  ava  2s .c  om*/
 * @param sizes
 * @param w
 * @param h
 * @return
 */
public static Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
    final double ASPECT_TOLERANCE = 0.1;
    double targetRatio = (double) w / h;
    if (sizes == null)
        return null;

    Size optimalSize = null;
    double minDiff = Double.MAX_VALUE;

    int targetHeight = h;

    // Try to find an size match aspect ratio and size
    for (Size size : sizes) {
        double ratio = (double) size.width / size.height;
        if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
            continue;
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }

    // Cannot find the one match the aspect ratio, ignore the requirement
    if (optimalSize == null) {
        minDiff = Double.MAX_VALUE;
        for (Size size : sizes) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}

From source file:Main.java

public static boolean isNotGray(int[] rgb) {
    return Math.abs(rgb[0] - rgb[1]) > GRAY_TOLERANCE || Math.abs(rgb[0] - rgb[2]) > GRAY_TOLERANCE;
}

From source file:Main.java

public static long anElectionTerm() {
    return Math.abs(deterministicDataSequence.nextLong());
}

From source file:Main.java

private static boolean isNotGray(int[] rgb) {
    return Math.abs(rgb[0] - rgb[1]) > GRAY_TOLERANCE || Math.abs(rgb[0] - rgb[2]) > GRAY_TOLERANCE;
}

From source file:Main.java

private static int leadingDigits(double d) {
    int digits = 0;
    while (Math.abs(d) >= 1) {
        digits++;//  w w w .j av a  2 s  .  c  o m
        d /= 10.0;
    }
    return digits;
}