List of usage examples for java.lang Float isNaN
public static boolean isNaN(float v)
From source file:Main.java
public static boolean isLikelyFloat(int value) { // Check for some common named float values // We don't check for Float.MIN_VALUE, which has an integer representation of 1 if (value == canonicalFloatNaN || value == maxFloat || value == piFloat || value == eFloat) { return true; }//from www . java 2s . co m // Check for some named integer values if (value == Integer.MAX_VALUE || value == Integer.MIN_VALUE) { return false; } // Check for likely resource id int packageId = value >> 24; int resourceType = value >> 16 & 0xff; int resourceId = value & 0xffff; if ((packageId == 0x7f || packageId == 1) && resourceType < 0x1f && resourceId < 0xfff) { return false; } // a non-canocical NaN is more likely to be an integer float floatValue = Float.intBitsToFloat(value); if (Float.isNaN(floatValue)) { return false; } // Otherwise, whichever has a shorter scientific notation representation is more likely. // Integer wins the tie String asInt = format.format(value); String asFloat = format.format(floatValue); // try to strip off any small imprecision near the end of the mantissa int decimalPoint = asFloat.indexOf('.'); int exponent = asFloat.indexOf("E"); int zeros = asFloat.indexOf("000"); if (zeros > decimalPoint && zeros < exponent) { asFloat = asFloat.substring(0, zeros) + asFloat.substring(exponent); } else { int nines = asFloat.indexOf("999"); if (nines > decimalPoint && nines < exponent) { asFloat = asFloat.substring(0, nines) + asFloat.substring(exponent); } } return asFloat.length() < asInt.length(); }
From source file:Main.java
/** * Creates and returns an unmodifiable List that wraps the given array. * Changes to the array will be reflected in the List. * @param arr The array to wrap as a List * @param fillValue The value to use in place of Float.NaNs * @return an unmodifiable List that wraps the array * @throws NullPointerException if the array is null *//*from www . j a v a 2s . c o m*/ public static List<Float> listFromFloatArray(final float[] arr, final Float fillValue) { if (arr == null) throw new NullPointerException("array cannot be null"); return new AbstractList<Float>() { @Override public Float get(int index) { float val = arr[index]; if (Float.isNaN(val)) { return fillValue; } else { return val; } // return Float.isNaN(val) ? fillValue : val; } @Override public int size() { return arr.length; } }; }
From source file:edu.nyu.vida.data_polygamy.scalar_function.Mode.java
@Override public void addValue(float value) { if (Float.isNaN(value)) return;/* w ww . j av a 2s. c o m*/ floatValues.add(value); count++; }
From source file:edu.nyu.vida.data_polygamy.scalar_function.Median.java
@Override public void addValue(float value) { if (Float.isNaN(value)) return;// w w w .jav a 2 s . c om floatValues.add(value); count++; }
From source file:Main.java
/** * <p>Returns the maximum value in an array.</p> * // w ww . j av a 2s . c o m * @param array an array, must not be null or empty * @return the minimum value in the array * @throws IllegalArgumentException if <code>array</code> is <code>null</code> * @throws IllegalArgumentException if <code>array</code> is empty * @see IEEE754rUtils#max(float[]) IEEE754rUtils for a version of this method that handles NaN differently */ public static float max(float[] array) { // Validates input if (array == null) { throw new IllegalArgumentException("The Array must not be null"); } else if (array.length == 0) { throw new IllegalArgumentException("Array cannot be empty."); } // Finds and returns max float max = array[0]; for (int j = 1; j < array.length; j++) { if (Float.isNaN(array[j])) { return Float.NaN; } if (array[j] > max) { max = array[j]; } } return max; }
From source file:Main.java
/** * <p>Returns the minimum value in an array.</p> * // w ww . j a v a2 s . c o m * @param array an array, must not be null or empty * @return the minimum value in the array * @throws IllegalArgumentException if <code>array</code> is <code>null</code> * @throws IllegalArgumentException if <code>array</code> is empty * @see IEEE754rUtils#min(float[]) IEEE754rUtils for a version of this method that handles NaN differently */ public static float min(float[] array) { // Validates input if (array == null) { throw new IllegalArgumentException("The Array must not be null"); } else if (array.length == 0) { throw new IllegalArgumentException("Array cannot be empty."); } // Finds and returns min float min = array[0]; for (int i = 1; i < array.length; i++) { if (Float.isNaN(array[i])) { return Float.NaN; } if (array[i] < min) { min = array[i]; } } return min; }
From source file:savant.selection.VariantPopup.java
@Override protected void initInfo() { if (record instanceof LDRecord) { LDRecord ldRec = (LDRecord) record; float dPrime = ldRec.getDPrime(); if (!Float.isNaN(dPrime)) { add(new JLabel(String.format("D\u2032: %.2f", dPrime))); }//from www .j av a2 s . co m add(new JLabel(String.format("r\u00B2: %.2f", ldRec.getRSquared()))); List<VariantRecord> varRecs = ldRec.getConstituents(); VariantRecord varRec0 = varRecs.get(0); VariantRecord varRec1 = varRecs.get(1); add(new JSeparator()); initVariantRecord(varRec0, null); add(new JSeparator()); initVariantRecord(varRec1, null); name = VariationController.getDisplayName(varRec0) + " vs. " + VariationController.getDisplayName(varRec1); start = Math.min(varRec0.getPosition(), varRec1.getPosition()); end = Math.max(varRec0.getPosition(), varRec1.getPosition()); } else { VariantRecord varRec; ParticipantRecord partRec = null; if (record instanceof VariantRecord) { varRec = (VariantRecord) record; } else { partRec = (ParticipantRecord) record; varRec = partRec.getVariantRecord(); } name = varRec.getName(); start = end = varRec.getPosition(); initVariantRecord(varRec, partRec); } }
From source file:org.broad.igv.data.ProcessingUtils.java
private static boolean nullDataCheck(float[] data) { // Check for null or missing data. Float.NaN is interpreted // as a placeholder for "no data. boolean noData = true; if ((data != null) && (data.length > 0)) { for (int i = 0; i < data.length; i++) { if (!Float.isNaN(data[i])) { noData = false;/*from w w w .j av a 2 s . com*/ break; } } } return noData; }
From source file:ru.histone.v2.evaluator.EvalUtils.java
public static boolean isNumeric(StringEvalNode evalNode) { try {//from ww w . jav a 2s . c om final Float value = parseFloat(evalNode.getValue()); return !Float.isNaN(value) && Float.isFinite(value); } catch (NumberFormatException e) { return false; } }
From source file:org.dbpedia.spotlight.lucene.similarity.NewSimilarity.java
private float round(float d) { float result = d; DecimalFormat twoDForm = new DecimalFormat("#.######"); if (Float.isInfinite(d)) { result = Float.MAX_VALUE; } else if (Float.isNaN(d)) { result = -2;// www. j a v a 2s.co m } else { result = Float.valueOf(twoDForm.format(d)); } return result; }