List of usage examples for java.lang Math abs
@HotSpotIntrinsicCandidate public static double abs(double a)
From source file:Main.java
private static int getTimeDistanceInMinutes(long time) { long timeDistance = currentDate().getTime() - time; return Math.round((Math.abs(timeDistance) / 1000) / 60); }
From source file:Main.java
public static long getCountDay(String date1) { String date2 = getDate();/*from ww w . j a v a 2s.c om*/ long day = getQuot(date1, date2); return Math.abs(day); }
From source file:Main.java
public static Bitmap subtract(Bitmap bitmap1, Bitmap bitmap2) { int width = bitmap1.getWidth(); int height = bitmap1.getHeight(); Bitmap grayBitmap1 = toGrayScale(bitmap1); Bitmap grayBitmap2 = toGrayScale(bitmap2); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) { int value1 = Color.blue(grayBitmap1.getPixel(x, y)); int value2 = Color.blue(grayBitmap2.getPixel(x, y)); int resultValue = Math.abs(value2 - value1); // resultValue = (resultValue>255/3)?resultValue:0; result.setPixel(x, y, Color.rgb(resultValue, resultValue, resultValue)); }//from w w w . j a va 2 s . co m // grayBitmap1.recycle(); // grayBitmap2.recycle(); return result; }
From source file:Main.java
public static double tile2lat(int y, int aZoom) { final double MerkElipsK = 0.0000001; final long sradiusa = 6378137; final long sradiusb = 6356752; final double FExct = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa; final int TilesAtZoom = 1 << aZoom; double result = (y - TilesAtZoom / 2) / -(TilesAtZoom / (2 * Math.PI)); result = (2 * Math.atan(Math.exp(result)) - Math.PI / 2) * 180 / Math.PI; double Zu = result / (180 / Math.PI); double yy = ((y) - TilesAtZoom / 2); double Zum1 = Zu; Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct)) / (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI))) * Math.pow(1 + FExct * Math.sin(Zum1), FExct))); while (Math.abs(Zum1 - Zu) >= MerkElipsK) { Zum1 = Zu;/*from w ww .j a v a2 s. c o m*/ Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct)) / (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI))) * Math.pow(1 + FExct * Math.sin(Zum1), FExct))); } result = Zu * 180 / Math.PI; return result; }
From source file:dtu.ds.warnme.utils.RandomUtils.java
public static boolean compareFloat(float a, float b, int precision) { return Math.abs(a - b) <= Math.pow(10, -precision); }
From source file:Main.java
/** * Tests whether the two decimal numbers are equal with a tolerance of 0.01. * * @param d1 the first value.//from ww w . ja va2 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) { return Math.abs(d1 - d2) < TOLERANCE; }
From source file:Main.java
/** * @return the size written, in bytes. Always 3 bytes. *//*w w w . j av a 2 s . com*/ static int writeSInt24ToStream(final OutputStream destination, final int value) throws IOException { final int absValue = Math.abs(value); destination.write((byte) (((value < 0 ? 0x80 : 0) | (absValue >> 16)) & 0xFF)); destination.write((byte) ((absValue >> 8) & 0xFF)); destination.write((byte) (absValue & 0xFF)); return 3; }
From source file:Main.java
private static String getDayOfWeek(String format, int calendarField) { String strDate = null;/*from w ww. j av a2 s . c o m*/ try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format, Locale.CHINA); int week = c.get(Calendar.DAY_OF_WEEK); if (week == calendarField) { strDate = mSimpleDateFormat.format(c.getTime()); } else { int offectDay = calendarField - week; if (calendarField == Calendar.SUNDAY) { offectDay = 7 - Math.abs(offectDay); } c.add(Calendar.DATE, offectDay); strDate = mSimpleDateFormat.format(c.getTime()); } } catch (Exception e) { e.printStackTrace(); } return strDate; }
From source file:Main.java
public static float easeInOut(float n) { double q = 0.48f - n / DURATION / 1.04f, Q = Math.sqrt(0.1734f + q * q), x = Q - q, X = Math.pow(Math.abs(x), 1 / 3) * (x < 0 ? -1 : 1), y = -Q - q, Y = Math.pow(Math.abs(y), 1 / 3) * (y < 0 ? -1 : 1), t = X + Y + 0.5f; return (float) (DOMAIN * ((1 - t) * 3 * t * t + t * t * t) + START); }
From source file:Main.java
public static int[] generateCodePointSet(final int codePointSetSize, final Random random) { final int[] codePointSet = new int[codePointSetSize]; for (int i = codePointSet.length - 1; i >= 0;) { final int r = Math.abs(random.nextInt()); if (r < 0) continue; // Don't insert 0~0x20, but insert any other code point. // Code points are in the range 0~0x10FFFF. final int candidateCodePoint = 0x20 + r % (Character.MAX_CODE_POINT - 0x20); // Code points between MIN_ and MAX_SURROGATE are not valid on their own. if (candidateCodePoint >= Character.MIN_SURROGATE && candidateCodePoint <= Character.MAX_SURROGATE) continue; codePointSet[i] = candidateCodePoint; --i;/*w w w . j a v a 2 s . com*/ } return codePointSet; }