List of usage examples for java.lang Math signum
public static float signum(float f)
From source file:Main.java
public static void main(String[] args) { float x = 12.34f; float y = -4f; // call signum for both floats and print the result System.out.println("Math.signum(" + x + ")=" + Math.signum(x)); System.out.println("Math.signum(" + y + ")=" + Math.signum(y)); }
From source file:Main.java
public static void main(String[] args) { double x = 12.34; double y = -4; // call signum for both doubles and print the result System.out.println("Math.signum(" + x + ")=" + Math.signum(x)); System.out.println("Math.signum(" + y + ")=" + Math.signum(y)); }
From source file:Main.java
public static void main(String[] args) { int a = 10;// ww w. ja va 2 s .com int b = -50; int c = 3; double x = 25.0; double y = 3.0; double z = 4.0; System.out.println("abs(b) = " + Math.abs(b)); System.out.println("cbrt(x) = " + Math.cbrt(x)); System.out.println("exp(y) = " + Math.exp(z)); System.out.println("hypot(y, z)= " + Math.hypot(y, z)); System.out.println("log(y) = " + Math.log(y)); System.out.println("log10(y) = " + Math.log10(y)); System.out.println("max(a, b) = " + Math.max(a, b)); System.out.println("min(a, b) = " + Math.min(a, b)); System.out.println("pow(a, c) = " + Math.pow(a, c)); System.out.println("random() = " + Math.random()); System.out.println("signum(b) = " + Math.signum(b)); System.out.println("sqrt(x) = " + Math.sqrt(y)); }
From source file:Main.java
public static int compareLongs(@Nullable Long one, @Nullable Long another, boolean ascending) { return one != null ? (another != null//from w w w. j a v a 2 s . c om ? !ascending ? (int) Math.signum(another - one) : (int) Math.signum(one - another) : 1) : -1; }
From source file:Main.java
public static int compareFloats(@Nullable Float one, @Nullable Float another, boolean ascending) { return one != null ? (another != null//from www.ja va 2s . c o m ? !ascending ? (int) Math.signum(another - one) : (int) Math.signum(one - another) : 1) : -1; }
From source file:Main.java
public static int compareInts(@Nullable Integer one, @Nullable Integer another, boolean ascending) { return one != null ? (another != null/*from w w w . ja v a 2s .c o m*/ ? !ascending ? (int) Math.signum(another - one) : (int) Math.signum(one - another) : 1) : -1; }
From source file:Main.java
public static int compareDouble(@Nullable Double one, @Nullable Double another, boolean ascending) { return one != null ? (another != null// ww w .jav a2s . com ? !ascending ? (int) Math.signum(another - one) : (int) Math.signum(one - another) : 1) : -1; }
From source file:Main.java
public static String generateHashWhereClause(double lat, double lng) { double latHash = (lat + 180) / LATLON_SECTION; double lngHash = (lng + 180) / LATLON_SECTION; int latHashRounded = (int) Math.round(latHash); int lngHashRounded = (int) Math.round(lngHash); int iHash = getHash(latHashRounded, lngHashRounded); String whereClause = "hash = " + iHash; int nearbyLat = 0; int nearbyLng = 0; double overlap = LATLON_SECTION_EDGE; if (Math.abs(latHash - latHashRounded) > (0.5 - overlap)) nearbyLat = (int) Math.signum(latHash - latHashRounded); if (Math.abs(lngHash - lngHashRounded) > (0.5 - overlap)) nearbyLng = (int) Math.signum(lngHash - lngHashRounded); if (nearbyLat != 0) whereClause += " OR hash = " + getHash(latHashRounded + nearbyLat, lngHashRounded); if (nearbyLng != 0) whereClause += " OR hash = " + getHash(latHashRounded, lngHashRounded + nearbyLng); if ((nearbyLat != 0) && (nearbyLng != 0)) whereClause += " OR hash = " + getHash(latHashRounded + nearbyLat, lngHashRounded + nearbyLng); Log.d(TAG,//from ww w . j av a2 s . com "HotspotDbHelper generateHashWhereClause lat: " + lat + " lon: " + lng + " Where: " + whereClause); return whereClause; }
From source file:MyComparator.java
public int compare(Entry o1, Entry o2) { Double valueOne = (Double) o1.getValue(); Double valueTwo = (Double) o2.getValue(); return (int) Math.signum(valueOne.compareTo(valueTwo)); }
From source file:Main.java
public static <T> void testComparator(List<? extends T> list, Comparator<T> comparator) { for (int i = 0; i < list.size(); i++) { for (int j = i; j < list.size(); j++) { T oi = list.get(i);/* w w w . j a va 2 s. c om*/ T oj = list.get(j); int ci = comparator.compare(oi, oj); int cj = comparator.compare(oj, oi); if (Math.signum(ci) != -Math.signum(cj)) { throw new RuntimeException("Bad comparator: " + comparator + "\n\tlist.get(" + i + "): " + oi + "\n\tlist.get(" + j + "): " + oj + "\ncompare(list.get(" + i + "), list.get(" + j + ")): " + ci + "\ncompare(list.get(" + j + "), list.get(" + i + ")): " + cj); } } } }