List of usage examples for java.lang Math abs
@HotSpotIntrinsicCandidate public static double abs(double a)
From source file:Main.java
private static int getRawAmplitude(byte[] data, int len) { if (len <= 0 || data == null || data.length <= 0) { return 0; }// w ww .ja v a2 s . c om int sum = 0; for (int i = 0; i < len; i++) { sum += Math.abs(data[i]); } return sum / len; }
From source file:Main.java
/** * @param min/*from w w w . j av a 2 s . co m*/ * @param max * @return */ public static String getYZM(final int min, final int max) { Random random = new Random(); int randomnum = 0; int tmp = Math.abs(random.nextInt()); randomnum = tmp % (max - min + 1) + min; return randomnum + ""; }
From source file:Main.java
public static double[] Rec2Sph(double x, double y, double z) { double[] sph = new double[3]; sph[0] = Math.sqrt(x * x + y * y + z * z); sph[1] = x == 0 ? 0 : Math.atan(Math.abs(y / x)); if (x < 0) sph[1] = Math.PI - sph[1]; if (y < 0) sph[1] *= -1;/*from ww w.j av a 2s.com*/ sph[2] = Math.asin(z / sph[0]); return sph; }
From source file:Main.java
public static boolean isHit(int left1, int top1, int w1, int h1, int left2, int top2, int w2, int h2) { int x1 = left1 + w1 / 2; int y1 = top1 + h1 / 2; int x2 = left2 + w2 / 2; int y2 = top2 + h2 / 2; if (Math.abs(x1 - x2) < (w1 / 2 + w2 / 2) - 10 && Math.abs(y1 - y2) < (h1 / 2 + h2 / 2) - 10) { return true; }//from w w w . j a v a 2 s. c o m return false; }
From source file:Main.java
public static double getAcceleration(SensorEvent event) { final float x = event.values[0]; final float y = event.values[1]; final float z = event.values[2]; double sqrt = Math.sqrt(Math.abs(x * x) + Math.abs(y * y) + Math.abs(z * z)); return sqrt;//w w w.j a v a 2s.c om }
From source file:Main.java
public static boolean isAspectRatio4_3(int width, int height) { if (width < height) { int tmp = width; width = height;//from w ww. jav a 2s .c o m height = tmp; } double ratio = (double) width / height; if (Math.abs(ratio - 4.0 / 3.0) < 0.02) { return true; } return false; }
From source file:Main.java
/** Returns a random integer between 0 and n-1 */ public static int nextInt(int n) { Random rand = new Random(seed); return Math.abs(rand.nextInt()) % n; }
From source file:Main.java
public static boolean isAspectRatio16_9(int width, int height) { if (width < height) { int tmp = width; width = height;/*from w ww . j av a2s.c o m*/ height = tmp; } double ratio = (double) width / height; if (Math.abs(ratio - 16.0 / 9.0) < 0.02) { return true; } return false; }
From source file:Main.java
public static String declensionByNumber(int number, String[] words) { int wordIndex = 2; if (words.length != 3) { return null; }// www . java 2 s . c om int num = Math.abs(number) % 100; int numX = num % 10; if (num > 10 && num < 20) { wordIndex = 2; } else if (numX > 1 && numX < 5) { wordIndex = 1; } else if (numX == 1) { wordIndex = 0; } return words[wordIndex]; }
From source file:Main.java
public static List<Integer> toAbsIntegerList(final List<Integer> array) { final ArrayList<Integer> retValue = new ArrayList<Integer>(); for (final Integer item : array) retValue.add(Math.abs(item)); return retValue; }