List of usage examples for java.lang Math abs
@HotSpotIntrinsicCandidate public static double abs(double a)
From source file:Main.java
private static int[] adaptPreviewFps(int expectedFps, List<int[]> fpsRanges) { expectedFps *= 1000;//from w w w.j av a2s . c o m int[] closestRange = fpsRanges.get(0); int measure = Math.abs(closestRange[0] - expectedFps) + Math.abs(closestRange[1] - expectedFps); for (int[] range : fpsRanges) { if (range[0] <= expectedFps && range[1] >= expectedFps) { int curMeasure = Math.abs(range[0] - expectedFps) + Math.abs(range[1] - expectedFps); if (curMeasure < measure) { closestRange = range; measure = curMeasure; } } } return closestRange; }
From source file:Main.java
public static String getRandomStr(int len) { Random rd = new Random(); String retStr = ""; do {// ww w. j av a2 s .co m int rdGet1 = Math.abs(rd.nextInt()) % 10; int rdGet2 = Math.abs(rd.nextInt()) % 26 + 65; retStr = retStr + rdGet1 + (char) rdGet2; } while (retStr.length() < len); return retStr; }
From source file:Main.java
public static boolean move(float[] values, float[] preAccelerometerValues) { float difx = Math.abs(values[SensorManager.DATA_X]); float dify = Math.abs(values[SensorManager.DATA_Y]); float difz = Math.abs(values[SensorManager.DATA_Z]); Log.e("log.e val = ", " " + difx + " " + dify + " " + difz); float difx1 = Math.abs(preAccelerometerValues[SensorManager.DATA_X]); float dify1 = Math.abs(preAccelerometerValues[SensorManager.DATA_Y]); float difz1 = Math.abs(preAccelerometerValues[SensorManager.DATA_Z]); Log.e("log.e pre = ", " " + difx1 + " " + dify1 + " " + difz1); float difx2 = Math.abs(values[SensorManager.DATA_X] - preAccelerometerValues[SensorManager.DATA_X]); float dify2 = Math.abs(values[SensorManager.DATA_Y] - preAccelerometerValues[SensorManager.DATA_Y]); float difz2 = Math.abs(values[SensorManager.DATA_Z] - preAccelerometerValues[SensorManager.DATA_Z]); Log.e("log.e dif = ", " " + difx2 + " " + dify2 + " " + difz2); if (checkMove(values[SensorManager.DATA_X], preAccelerometerValues[SensorManager.DATA_X]) || checkMove(values[SensorManager.DATA_Y], preAccelerometerValues[SensorManager.DATA_Y]) || checkMove(values[SensorManager.DATA_Z], preAccelerometerValues[SensorManager.DATA_Z])) { return true; }//w w w .j ava2s. c o m return false; }
From source file:Main.java
/** * use and random value,maybe this can provide good experince * * @param min//from ww w. j ava 2 s .c o m * @param max * @return */ public static int getRandom(int min, int max) { Random random = new Random(); return random.nextInt(Math.abs(max - min)) + min; }
From source file:Main.java
/** * get a random number//from ww w .j av a 2 s . c o m * @param size e.g. 3: {0,1,2} * @param offset e.g. 1:{1,2,3}, -1:{-1,0,1} * @return random + offset */ public static int getRandom(int size, int offset) { int random = ((int) System.currentTimeMillis() % size); random = Math.abs(random); random += offset; return random; }
From source file:Main.java
public static double convertKMToMiles(String kilometers) { DecimalFormat decimalFormat = new DecimalFormat("#"); int km = Integer.parseInt(kilometers); double miles = 0.621 * km; decimalFormat.format(miles);//from w w w . j av a 2 s .c o m return Math.abs(miles); }
From source file:Main.java
/** * calculate difference form two dates Note: both dates are in same format. * * @param mDate1 date 1/* w w w . j av a 2 s . co m*/ * @param mDate2 date 2 * @return date difference in long */ public static long calculateDays(Date mDate1, Date mDate2) { return Math.abs((mDate1.getTime() - mDate2.getTime()) / (24 * 60 * 60 * 1000) + 1); }
From source file:Main.java
public static byte[] fromUnsigned(int[] ubytes) { if (ubytes == null) return null; byte[] res = new byte[ubytes.length]; int ubyte = 0; for (int i = 0; i < ubytes.length; i++) { ubyte = Math.abs(ubytes[i]) % 256; res[i] = (byte) (ubyte >= 128 ? ubyte - 256 : ubyte); }//from w w w. ja va 2 s .c om return res; }
From source file:Main.java
public static <O> O getRandom(final Collection<O> pObjects) { if (pObjects != null && !pObjects.isEmpty()) { int r = Math.abs(random.nextInt() % pObjects.size()); List<O> objects = !(pObjects instanceof List) ? new ArrayList<O>(pObjects) : (List<O>) pObjects; return objects.get(r); }//ww w . j av a 2 s. c om return null; }
From source file:Main.java
public static float distanceBetween2Points(float vectorX0, float vectorY0, float vectorXP, float vectorYP) { float x = Math.abs(vectorXP - vectorX0); float y = Math.abs(vectorYP - vectorY0); return (float) Math.sqrt((x * x) + (y * y)); }