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

/**
 *
 * @param d eot in hours//from  w  w  w.  ja v a 2  s .c o m
 * @return formatted string
 */
public final static String eotToString(double d) {
    int m = (int) Math.floor(Math.abs(d) * 60d);
    int s = (int) Math.round((3600d * Math.abs(d)) - (m * 60d));
    return ((d > 0 ? "+" : "-") + Integer.toString(m) + "m" + Integer.toString(s) + "s");
}

From source file:Main.java

private static boolean checkMove(float f, float g) {
    double thisdif = f - g;
    if (Math.abs(thisdif) > dif) {
        return true;
    }// www  .ja v  a 2  s  . c  om
    return false;

}

From source file:Main.java

private static double getRatioGap(Size size, double wantRatio) {
    double sizeRatio = (double) size.height / (double) size.width;
    return Math.abs(sizeRatio - wantRatio);
}

From source file:Main.java

public static boolean isCircleHit(int x, int y, int radius, int left, int top, int width, int height) {
    int x2 = left + width / 2;
    int y2 = top + height / 2;
    if (Math.abs(x - x2) < (radius + width / 2) && Math.abs(y - y2) < (radius + height / 2)) {
        return true;
    }/*w  w  w  .j  a  v a 2 s  .  c o m*/
    return false;
}

From source file:Main.java

public static Rectangle getRectangle(Point p1, Point p2) {
    return new Rectangle(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y), Math.abs(p1.x - p2.x),
            Math.abs(p1.y - p2.y));
}

From source file:Main.java

public static short audioRange(short[] track) { //Returns largest amplitude ("volume") of an audio track
    short range = 0;
    for (int i = 0; i < track.length; i++) {
        if (Math.abs(track[i]) > range)
            range = (short) Math.abs(track[i]);
    }//  www  .  ja v  a2  s  .  c o  m
    return range;
}

From source file:Main.java

/**
 * @return True if close enough//from  w w  w . j  ava2s.c  o  m
 */
public static boolean verifyPixelWithThreshold(int color, int expectedColor, int threshold) {
    int diff = Math.abs(Color.red(color) - Color.red(expectedColor))
            + Math.abs(Color.green(color) - Color.green(expectedColor))
            + Math.abs(Color.blue(color) - Color.blue(expectedColor));
    return diff <= threshold;
}

From source file:Main.java

static int nextInt(int a, int b) {
    return Math.min(a, b) + random.nextInt(Math.abs(a - b));
}

From source file:Main.java

public static double transformLon(double x, double y) {
    double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
    ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
    ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
    ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;
    return ret;//  w w  w . j a v  a2 s .c  om
}

From source file:Main.java

/**
 * Check if one double value equals to zero
 * @param obj/*from  w  w  w  .  ja v  a 2 s  .  co m*/
 * @param precision
 * @return
 */
public static boolean equalsToZero(double obj, int precision) {
    return Math.abs(obj) <= Math.pow(0.1, precision);
}