List of usage examples for java.lang Math max
@HotSpotIntrinsicCandidate public static double max(double a, double b)
From source file:Main.java
public static String escapeHtml(String s) { final StringBuilder out = new StringBuilder(Math.max(16, s.length())); for (int i = 0; i < s.length(); i++) { final char c = s.charAt(i); if (c > 127 || c == '"' || c == '<' || c == '>' || c == '&') { out.append("&#"); out.append((int) c); out.append(';'); } else {//from www. ja v a2s. c o m out.append(c); } } return out.toString(); }
From source file:Main.java
public static int getSampleSizeAutoFitToScreen(int paramInt1, int paramInt2, int paramInt3, int paramInt4) { if ((paramInt2 == 0) || (paramInt1 == 0)) return 1; return Math.min(Math.max(paramInt3 / paramInt1, paramInt4 / paramInt2), Math.max(paramInt4 / paramInt1, paramInt3 / paramInt2)); }
From source file:Main.java
public static int getSampleSizeAutoFitToScreen(int vWidth, int vHeight, int bWidth, int bHeight) { if (vHeight == 0 || vWidth == 0) { return 1; }/*from w ww . j ava2 s . co m*/ int ratio = Math.max(bWidth / vWidth, bHeight / vHeight); int ratioAfterRotate = Math.max(bHeight / vWidth, bWidth / vHeight); return Math.min(ratio, ratioAfterRotate); }
From source file:Main.java
public static Bitmap resizeOuterFit(Bitmap src, Rect rect) { float aspectRatio = Math.max((float) rect.width() / src.getWidth(), (float) rect.height() / src.getHeight()); int newWidth = (int) (src.getWidth() * aspectRatio); int newHeight = (int) (src.getHeight() * aspectRatio); return Bitmap.createScaledBitmap(src, newWidth, newHeight, false); }
From source file:Main.java
public static byte[] generateJSF(BigInteger g, BigInteger h) { int digits = Math.max(g.bitLength(), h.bitLength()) + 1; byte[] jsf = new byte[digits]; BigInteger k0 = g, k1 = h;/*from w w w . j a v a 2 s .com*/ int j = 0, d0 = 0, d1 = 0; while (k0.signum() > 0 || k1.signum() > 0 || d0 > 0 || d1 > 0) { int n0 = (k0.intValue() + d0) & 7, n1 = (k1.intValue() + d1) & 7; int u0 = n0 & 1; if (u0 != 0) { u0 -= (n0 & 2); if ((n0 + u0) == 4 && (n1 & 3) == 2) { u0 = -u0; } } int u1 = n1 & 1; if (u1 != 0) { u1 -= (n1 & 2); if ((n1 + u1) == 4 && (n0 & 3) == 2) { u1 = -u1; } } if ((d0 << 1) == 1 + u0) { d0 = 1 - d0; } if ((d1 << 1) == 1 + u1) { d1 = 1 - d1; } k0 = k0.shiftRight(1); k1 = k1.shiftRight(1); jsf[j++] = (byte) ((u0 << 4) | (u1 & 0xF)); } // Reduce the JSF array to its actual length if (jsf.length > j) { jsf = trim(jsf, j); } return jsf; }
From source file:Main.java
public static String getDifficultyName(int val) { val = Math.min(val / 5, difficultyStrings.length - 1); val = Math.max(val, 0); return difficultyStrings[val]; }
From source file:Main.java
/** * @param alpha 0...255/*from w w w . ja v a 2s . c o m*/ */ public static int setColorAlpha(int color, float alpha) { return Color.argb(Math.min(Math.max((int) (alpha * 255.0f), 0), 255), Color.red(color), Color.green(color), Color.blue(color)); }
From source file:Main.java
public static byte[] generateJSF(BigInteger g, BigInteger h) { int digits = Math.max(g.bitLength(), h.bitLength()) + 1; byte[] jsf = new byte[digits]; BigInteger k0 = g, k1 = h;/*from ww w. ja va 2s . c o m*/ int j = 0, d0 = 0, d1 = 0; int offset = 0; while ((d0 | d1) != 0 || k0.bitLength() > offset || k1.bitLength() > offset) { int n0 = ((k0.intValue() >>> offset) + d0) & 7, n1 = ((k1.intValue() >>> offset) + d1) & 7; int u0 = n0 & 1; if (u0 != 0) { u0 -= (n0 & 2); if ((n0 + u0) == 4 && (n1 & 3) == 2) { u0 = -u0; } } int u1 = n1 & 1; if (u1 != 0) { u1 -= (n1 & 2); if ((n1 + u1) == 4 && (n0 & 3) == 2) { u1 = -u1; } } if ((d0 << 1) == 1 + u0) { d0 ^= 1; } if ((d1 << 1) == 1 + u1) { d1 ^= 1; } if (++offset == 30) { offset = 0; k0 = k0.shiftRight(30); k1 = k1.shiftRight(30); } jsf[j++] = (byte) ((u0 << 4) | (u1 & 0xF)); } // Reduce the JSF array to its actual length if (jsf.length > j) { jsf = trim(jsf, j); } return jsf; }
From source file:Main.java
private static int normalizeDouble(double f) { double f2 = Math.max(0.0, Math.min(1.0, f)); return (int) Math.floor(f2 == 1.0 ? COLOR_FLOAT_TO_INT_FACTOR : f2 * (COLOR_FLOAT_TO_INT_FACTOR + 1)); }
From source file:Main.java
public static byte[] generateJSF(BigInteger g, BigInteger h) { byte[] jsf = new byte[(Math.max(g.bitLength(), h.bitLength()) + 1)]; BigInteger k0 = g;/*from www . j a va2 s. c o m*/ BigInteger k1 = h; int d0 = 0; int d1 = 0; int offset = 0; int j = 0; while (true) { if ((d0 | d1) == 0 && k0.bitLength() <= offset && k1.bitLength() <= offset) { break; } int n0 = ((k0.intValue() >>> offset) + d0) & 7; int n1 = ((k1.intValue() >>> offset) + d1) & 7; int u0 = n0 & 1; if (u0 != 0) { u0 -= n0 & 2; if (n0 + u0 == 4 && (n1 & 3) == 2) { u0 = -u0; } } int u1 = n1 & 1; if (u1 != 0) { u1 -= n1 & 2; if (n1 + u1 == 4 && (n0 & 3) == 2) { u1 = -u1; } } if ((d0 << 1) == u0 + 1) { d0 ^= 1; } if ((d1 << 1) == u1 + 1) { d1 ^= 1; } offset++; if (offset == 30) { offset = 0; k0 = k0.shiftRight(30); k1 = k1.shiftRight(30); } int j2 = j + 1; jsf[j] = (byte) ((u0 << 4) | (u1 & 15)); j = j2; } if (jsf.length > j) { return trim(jsf, j); } return jsf; }