List of usage examples for java.lang Math pow
@HotSpotIntrinsicCandidate public static double pow(double a, double b)
From source file:Main.java
public static float norm2(float[] vec) { float sum = 0; for (float f : vec) { sum += Math.pow(f, 2); }/*from w w w.j av a 2 s . c o m*/ return (float) Math.sqrt(sum); }
From source file:Main.java
/** Calculates the contrast between the given color and white, using the algorithm provided by * the WCAG v2 in http://www.w3.org/TR/WCAG20/#contrast-ratiodef. */// www .j a v a 2 s . c om private static float getContrastForColor(int color) { float bgR = Color.red(color) / 255f; float bgG = Color.green(color) / 255f; float bgB = Color.blue(color) / 255f; bgR = (bgR < 0.03928f) ? bgR / 12.92f : (float) Math.pow((bgR + 0.055f) / 1.055f, 2.4f); bgG = (bgG < 0.03928f) ? bgG / 12.92f : (float) Math.pow((bgG + 0.055f) / 1.055f, 2.4f); bgB = (bgB < 0.03928f) ? bgB / 12.92f : (float) Math.pow((bgB + 0.055f) / 1.055f, 2.4f); float bgL = 0.2126f * bgR + 0.7152f * bgG + 0.0722f * bgB; return Math.abs((1.05f) / (bgL + 0.05f)); }
From source file:Main.java
/** * Returns a List of Lists: all combinations of the elements of the given * List./*from www. jav a 2s . co m*/ * * @param maxCombinationSize combinations larger than this value are * discarded * @param mandatoryItem an item that all returned combinations must contain, * or null to leave unspecified */ public static List combinations(List original, int maxCombinationSize, Object mandatoryItem) { ArrayList combinations = new ArrayList(); //Combinations are given by the bits of each binary number from 1 to 2^N for (int i = 1; i <= ((int) Math.pow(2, original.size()) - 1); i++) { ArrayList combination = new ArrayList(); for (int j = 0; j < original.size(); j++) { if ((i & (int) Math.pow(2, j)) > 0) { combination.add(original.get(j)); } } if (combination.size() > maxCombinationSize) { continue; } if ((mandatoryItem != null) && !combination.contains(mandatoryItem)) { continue; } combinations.add(combination); } return combinations; }
From source file:Main.java
/** * Convert XYZ to RGB.// w w w. j a v a2s . co m * * Convert equation and source code is from ImageJ's plugin Color Space Converter * http://rsbweb.nih.gov/ij/plugins/download/Color_Space_Converter.java * * @param X * @param Y * @param Z * @return RGB in int array. */ private static int[] XYZtoRGB(double X, double Y, double Z) { int[] result = new int[3]; double x = X / 100.0; double y = Y / 100.0; double z = Z / 100.0; // [r g b] = [X Y Z][Mi] double r = (x * Mi[0][0]) + (y * Mi[0][1]) + (z * Mi[0][2]); double g = (x * Mi[1][0]) + (y * Mi[1][1]) + (z * Mi[1][2]); double b = (x * Mi[2][0]) + (y * Mi[2][1]) + (z * Mi[2][2]); // assume sRGB if (r > 0.0031308) { r = ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055); } else { r = (r * 12.92); } if (g > 0.0031308) { g = ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055); } else { g = (g * 12.92); } if (b > 0.0031308) { b = ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055); } else { b = (b * 12.92); } r = (r < 0) ? 0 : r; g = (g < 0) ? 0 : g; b = (b < 0) ? 0 : b; // convert 0..1 into 0..255 result[0] = (int) Math.round(r * 255); result[1] = (int) Math.round(g * 255); result[2] = (int) Math.round(b * 255); return result; }
From source file:edu.msu.cme.rdp.graph.sandbox.BloomFilterInterrogator.java
public static void printStats(BloomFilter filter, PrintStream out) { long n = filter.getUniqueKmers(); long m = (long) Math.pow(2, filter.getHashSizeLog2()); int k = filter.getHashCount(); //(1-e^(-k*((n+.5)/(m-1))))^k double falsePositiveRate = Math.pow((1 - Math.pow(Math.E, -k * ((n + .5) / (m - 1)))), k); out.println("Bloom filter created on: " + filter.getCreatedOn()); out.println("Serializable id: " + BloomFilter.serialVersionUID); out.println();/*from w w w .j a v a2 s .c o m*/ out.println("Bloom filter size log 2: " + filter.getHashSizeLog2()); out.println("Bloom filter size (bits) (m): " + m); out.println(); out.println("Number of bitsets: " + filter.getNumBitsets()); out.println("Bitset size (bits): " + filter.getBitsetSize()); out.println("Bitset size log2: " + filter.getBitsetSizeLog2()); out.println(); out.println("Number of hashes (k): " + filter.getHashCount()); out.println("Hash function name: " + filter.getHasherClassName()); out.println(); out.println("Bitset Mask: " + StringUtils.leftPad(Long.toBinaryString(filter.getBitsetMask()), 64, '0')); out.println("Hash mask: " + StringUtils.leftPad(Long.toBinaryString(filter.getHashMask()), 64, '0')); out.println(); out.println("Kmer length: " + filter.getKmerSize()); out.println(); out.println("Total kmers in bloom filter: " + filter.getTotalKmers()); out.println("Total strings inserted: " + filter.getTotalStrings()); out.println("Total unique kmers: " + filter.getUniqueKmers()); out.println("Predicted false positive rate: " + falsePositiveRate); }
From source file:Main.java
/** * Computes the Euclidean distance between the two colors * * @param color1 the first color/* w ww. jav a 2s .co m*/ * @param color2 the color to compare with * @return the distance between the two colors */ private static double getColorDistanceRgb(int color1, int color2) { double r, g, b; r = Math.pow(Color.red(color2) - Color.red(color1), 2.0); g = Math.pow(Color.green(color2) - Color.green(color1), 2.0); b = Math.pow(Color.blue(color2) - Color.blue(color1), 2.0); return Math.sqrt(b + g + r); }
From source file:Main.java
/** * Determine if the device is a 7 tablet * /*from www .j av a 2 s . c o m*/ * @param context * @return true if it is >= 6.5 and < 7.6 */ public static boolean is7InchTablet(Context context) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); float widthInInches = metrics.widthPixels / metrics.xdpi; float heightInInches = metrics.heightPixels / metrics.ydpi; double sizeInInches = Math.sqrt(Math.pow(widthInInches, 2) + Math.pow(heightInInches, 2)); return sizeInInches >= 6.5 && sizeInInches < 7.6; }
From source file:Main.java
public static String readableFileSize(long size) { if (size <= 0) return "0"; final String[] units = new String[] { "Byte", "KB", "MB", "GB", "TB" }; int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; }
From source file:Main.java
public static int generate(byte[] key, long t, int digits) { int r = 0;//from w w w.j a v a 2s . co m try { t /= 30; byte[] data = new byte[8]; long value = t; for (int i = 8; i-- > 0; value >>>= 8) { data[i] = (byte) value; } SecretKeySpec signKey = new SecretKeySpec(key, SHA1); Mac mac = Mac.getInstance(SHA1); mac.init(signKey); byte[] hash = mac.doFinal(data); int offset = hash[20 - 1] & 0xF; long truncatedHash = 0; for (int i = 0; i < 4; ++i) { truncatedHash <<= 8; truncatedHash |= (hash[offset + i] & 0xFF); } truncatedHash &= 0x7FFFFFFF; truncatedHash %= Math.pow(10, digits); r = (int) truncatedHash; } catch (Exception e) { } return r; }
From source file:Main.java
public static double humanSizeToBytes(String value) { String scalar;// w ww. jav a 2 s. c o m int unit = 1024; int exp; char c; double returnValue = 0; String[] words = value.split("\\s+"); // Log.d("Debug", "words length:" + words.length); if (words.length == 2) { // Log.d("Debug", "words[0]:" + words[0]); // Log.d("Debug", "words[1]:" + words[1]); try { scalar = words[0].replace(",", "."); // Log.d("Debug", "scalar:" + scalar); exp = "BKMGTPE".indexOf((words[1]).toCharArray()[0]); // Log.d("Debug", "exp:" + exp); returnValue = Double.parseDouble(scalar) * Math.pow(unit, exp); } catch (Exception e) { } } return returnValue; }