List of usage examples for java.lang Math abs
@HotSpotIntrinsicCandidate public static double abs(double a)
From source file:Main.java
public static int compareDateToDays(Date firstDate, Date lastDate) { if (firstDate == null || lastDate == null) { System.out.print("NULL"); }/*w w w . jav a 2 s . c o m*/ long time1 = firstDate.getTime(); long time2 = lastDate.getTime(); long tmpCal = time2 - time1; long mm = 24 * 60 * 60 * 1000; int days = (int) (tmpCal / mm); return Math.abs(days); }
From source file:Main.java
public static boolean isTouchFlick(float baseDistance, float[] startPoints, float[] endPoint) { float xDistance = endPoint[0] - startPoints[0]; float yDistance = endPoint[1] - startPoints[1]; if (Math.abs(xDistance) < baseDistance && Math.abs(yDistance) < baseDistance) { return false; }/* w w w . j a va 2 s . co m*/ return true; }
From source file:Main.java
/** * This method checks if the given value is within the deadband range. * If so, it returns 0.0 else it returns the unchanged value. * * @param value specifies the value to be chacked. * @param deadband specifies the deadband zone. * @return the value 0.0 if within deadband, unaltered otherwise. *//*from w w w. j av a 2s . c om*/ public static double applyDeadband(double value, double deadband) { return Math.abs(value) >= deadband ? value : 0.0; }
From source file:Main.java
public static int roundOrientation(int orientation, int orientationHistory) { boolean changeOrientation = false; if (orientationHistory == OrientationEventListener.ORIENTATION_UNKNOWN) { changeOrientation = true;//from ww w . ja v a2 s.com } else { int dist = Math.abs(orientation - orientationHistory); dist = Math.min(dist, 360 - dist); changeOrientation = (dist >= 45 + ORIENTATION_HYSTERESIS); } if (changeOrientation) { return ((orientation + 45) / 90 * 90) % 360; } return orientationHistory; }
From source file:Main.java
private static void printPassword() { String UPPER = "ABCDEFGHIJKLMNPQRSTUVWXYZ"; String LOWER = "abcdefghijklmnpqrstuvwxyz"; String NUMBER = "123456789"; String SPECIAL = "!@#$%&*+?"; Random randGen = new Random(); StringBuffer buf = new StringBuffer(); buf.append(LOWER.charAt(Math.abs(randGen.nextInt()) % LOWER.length())); buf.append(LOWER.charAt(Math.abs(randGen.nextInt()) % LOWER.length())); buf.append(NUMBER.charAt(Math.abs(randGen.nextInt()) % NUMBER.length())); for (int i = 0; i <= 4; i++) { buf.append(LOWER.charAt(Math.abs(randGen.nextInt()) % LOWER.length())); }// w w w . ja va 2s . c o m buf.append(UPPER.charAt(Math.abs(randGen.nextInt()) % UPPER.length())); buf.append(LOWER.charAt(Math.abs(randGen.nextInt()) % LOWER.length())); System.out.println(buf.toString()); }
From source file:Main.java
public static double absSum(double[] input) { double sum = 0; for (int i = 0; i < input.length; i++) { sum += Math.abs(input[i]); }//from w w w . j av a2 s.c om return sum; }
From source file:Main.java
static int daysBetween(Calendar day1, Calendar day2) { /**/*from w w w.j a va 2 s. c o m*/ * Saved some effort using the solution described here, * http://stackoverflow.com/a/28865648/1587370 */ Calendar dayOne = (Calendar) day1.clone(), dayTwo = (Calendar) day2.clone(); if (dayOne.get(Calendar.YEAR) == dayTwo.get(Calendar.YEAR)) { return Math.abs(dayOne.get(Calendar.DAY_OF_YEAR) - dayTwo.get(Calendar.DAY_OF_YEAR)); } else { if (dayTwo.get(Calendar.YEAR) > dayOne.get(Calendar.YEAR)) { //swap them Calendar temp = dayOne; dayOne = dayTwo; dayTwo = temp; } int extraDays = 0; int dayOneOriginalYearDays = dayOne.get(Calendar.DAY_OF_YEAR); while (dayOne.get(Calendar.YEAR) > dayTwo.get(Calendar.YEAR)) { dayOne.add(Calendar.YEAR, -1); // getActualMaximum() important for leap years extraDays += dayOne.getActualMaximum(Calendar.DAY_OF_YEAR); } return extraDays - dayTwo.get(Calendar.DAY_OF_YEAR) + dayOneOriginalYearDays; } }
From source file:Main.java
public static long compareMin(Date before, Date after) { if (before == null || after == null) { return 0l; }/* ww w .j av a 2s. com*/ long dif = 0; if (after.getTime() >= before.getTime()) { dif = after.getTime() - before.getTime(); } else if (after.getTime() < before.getTime()) { dif = after.getTime() + 86400000 - before.getTime(); } dif = Math.abs(dif); return dif / 60000; }
From source file:Main.java
public static Camera.Size getOptimalPreviewSizeByAspectRatio(List<Camera.Size> sizes, double aspectRatio) { if (sizes == null) return null; Camera.Size optimalSize = null;/*from w ww. ja v a 2 s . c om*/ // Find size for (Camera.Size size : sizes) { double ratio = (double) size.width / size.height; if (Math.abs(ratio - aspectRatio) > ASPECT_TOLERANCE) { continue; } if ((optimalSize == null) || (optimalSize.height < size.height)) { optimalSize = size; } } return optimalSize; }
From source file:Main.java
/** * Tests whether the two decimal numbers are equal with a tolerance of 0.01. * If one or both of the numbers are null, false is returned. * * @param d1 the first value./*from ww w . j av a 2 s . c o m*/ * @param d2 the second value. * @return true if the two decimal numbers are equal with a tolerance of 0.01. */ public static boolean isEqual(Double d1, Double d2) { if (d1 == null || d2 == null) { return false; } return Math.abs(d1 - d2) < TOLERANCE; }