List of usage examples for java.lang Math abs
@HotSpotIntrinsicCandidate public static double abs(double a)
From source file:Main.java
public static boolean isNearRatio16_9(int width, int height) { if (width < height) { int tmp = width; width = height;/*from w w w. j av a 2s . co m*/ height = tmp; } if (Math.abs((double) width / height - 4.0 / 3.0) > Math.abs((double) width / height - 16.0 / 9.0)) { return true; } return false; }
From source file:Main.java
/** * Method checks if two float numbers are similar. *//*from w ww.j a v a2 s. c om*/ public static boolean almostEqual(float a, float b, float absoluteDiff, float relativeDiff) { float diff = Math.abs(a - b); if (diff <= absoluteDiff) { return true; } a = Math.abs(a); b = Math.abs(b); float largest = (a > b) ? a : b; if (diff <= largest * relativeDiff) { return true; } return false; }
From source file:Main.java
public static double transformLat(double x, double y) { double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * 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(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0; ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0; return ret;/* w w w . j a v a 2s . c om*/ }
From source file:Main.java
static float nextFloat(float a, float b) { return Math.min(a, b) + random.nextFloat() * Math.abs(a - b); }
From source file:Main.java
/** * Calculate the angle to the target location from local. *///w w w. j av a 2s . c o m private static double getAngle(final double startheight, final double endheight, final float poslenght) { double radian = Math.atan(Math.abs((endheight - startheight)) / poslenght); double degree = Math.toDegrees(radian); if (startheight > endheight) { return -degree; } return degree; }
From source file:Main.java
/** * Calculate the angle to the target location from local. *//*from w w w . j a v a 2 s . c o m*/ private static double getAngle(final double startheight, final double endheight, final float poslength) { double radian = Math.atan(Math.abs((endheight - startheight)) / poslength); double degree = Math.toDegrees(radian); if (startheight > endheight) { return -degree; } return degree; }
From source file:Main.java
public static final int getRandom(int _min, int _max) { if (_min < 0 && _max < 0) { return randomGenerator.nextInt(Math.abs(_min - _max)) + _min; } else if (_min < 0) { return randomGenerator.nextInt(Math.abs(_min) + _max) + _min; } else {//from www. j a va 2s . c om return randomGenerator.nextInt(_max - _min) + _min; } }
From source file:Main.java
public static String getSigFig(double value, int n) { String result = String.format("%.10f", value); int k = (int) (Math.log(Math.abs(value)) / Math.log(10)); if ((k + 1) >= n) { // Assume value > 0 result = result.substring(0, n); } else {/*from w ww . j a v a 2 s . c o m*/ if (value < 0) { n = n + 1; } if (0 < Math.abs(value) && Math.abs(value) < 1) { n = n + 1; } if (value != 0) { result = result.substring(0, n + 1); } else { n = n + 2; result = "0.0"; } // Add trailing zeros while (result.length() < n) { result = result + "0"; } } return result; }
From source file:Main.java
public static String getRandomFileName() { String _df = android.text.format.DateFormat.format("MMddyyyyhhmmss", new java.util.Date()).toString(); Random r = new Random(); int random = Math.abs(r.nextInt() % 100); return String.format("%d%s.jpg", random, _df); }
From source file:Main.java
public static float calculateDuration(float startX, float startY, float endX, float endY, float maxDistance, int minDuaration, int maxDurationForFling) { float duation = Math.min( Math.max(Math.abs((endY - startY)), Math.abs((endX - startX))) / maxDistance * maxDurationForFling, maxDurationForFling);/* ww w . ja v a 2 s.co m*/ if (duation < minDuaration) { return minDuaration; } if (duation > maxDurationForFling) { return maxDurationForFling; } return duation; }