List of usage examples for java.lang Float NaN
float NaN
To view the source code for java.lang Float NaN.
Click Source Link
From source file:edu.harvard.iq.dataverse.util.SumStatCalculator.java
public static double[] calculateSummaryStatistics(Number[] x) { logger.fine("entering calculate summary statistics (" + x.length + " Number values);"); double[] nx = new double[8]; //("mean", "medn", "mode", "vald", "invd", "min", "max", "stdev"); Float testNanValue = new Float(Float.NaN); Number testNumberValue = testNanValue; if (Double.isNaN(testNumberValue.doubleValue())) { logger.fine("Float test NaN value is still recognized as a Double NaN."); }/*from w w w . ja v a 2 s . com*/ int invalid = countInvalidValues(x); nx[4] = invalid; logger.fine("counted invalid values: " + nx[4]); nx[3] = x.length - invalid; logger.fine("counted valid values: " + nx[3]); //double[] newx = prepareForSummaryStats(x); double[] newx = prepareForSummaryStatsAlternative(x, x.length - invalid); logger.fine("prepared double vector for summary stats calculation (" + newx.length + " double values);"); ////nx[0] = StatUtils.mean(newx); nx[0] = calculateMean(newx); logger.fine("calculated mean: " + nx[0]); ////nx[1] = StatUtils.percentile(newx, 50); nx[1] = calculateMedian(newx); logger.fine("calculated medn: " + nx[1]); nx[2] = 0.0; //getMode(newx); nx[5] = StatUtils.min(newx); logger.fine("calculated min: " + nx[5]); nx[6] = StatUtils.max(newx); logger.fine("calculated max: " + nx[6]); nx[7] = Math.sqrt(StatUtils.variance(newx)); logger.fine("calculated stdev: " + nx[7]); return nx; }
From source file:org.evosuite.utils.NumberFormatter.java
/** * <p>/*from ww w . j a v a2 s . c o m*/ * getNumberString * </p> * * @param value * a {@link java.lang.Object} object. * @return a {@link java.lang.String} object. */ public static String getNumberString(Object value) { if (value == null) return "null"; else if (value.getClass().equals(char.class) || value.getClass().equals(Character.class)) { // StringEscapeUtils fails to escape a single quote char if (Character.valueOf('\'').equals(value)) { return "'\\\''"; } else { return "'" + StringEscapeUtils.escapeJava(Character.toString((Character) value)) + "'"; } } else if (value.getClass().equals(String.class)) { return "\"" + StringEscapeUtils.escapeJava((String) value) + "\""; } else if (value.getClass().equals(float.class) || value.getClass().equals(Float.class)) { if (value.toString().equals("" + Float.NaN)) return "Float.NaN"; else if (value.toString().equals("" + Float.NEGATIVE_INFINITY)) return "Float.NEGATIVE_INFINITY"; else if (value.toString().equals("" + Float.POSITIVE_INFINITY)) return "Float.POSITIVE_INFINITY"; else if (((Float) value) < 0F) return "(" + value + "F)"; else return value + "F"; } else if (value.getClass().equals(double.class) || value.getClass().equals(Double.class)) { if (value.toString().equals("" + Double.NaN)) return "Double.NaN"; else if (value.toString().equals("" + Double.NEGATIVE_INFINITY)) return "Double.NEGATIVE_INFINITY"; else if (value.toString().equals("" + Double.POSITIVE_INFINITY)) return "Double.POSITIVE_INFINITY"; else if (((Double) value) < 0.0) return "(" + value + ")"; else return value.toString(); } else if (value.getClass().equals(long.class) || value.getClass().equals(Long.class)) { if (((Long) value) < 0) return "(" + value + "L)"; else return value + "L"; } else if (value.getClass().equals(byte.class) || value.getClass().equals(Byte.class)) { if (((Byte) value) < 0) return "(byte) (" + value + ")"; else return "(byte)" + value; } else if (value.getClass().equals(short.class) || value.getClass().equals(Short.class)) { if (((Short) value) < 0) return "(short) (" + value + ")"; else return "(short)" + value; } else if (value.getClass().equals(int.class) || value.getClass().equals(Integer.class)) { int val = ((Integer) value).intValue(); if (val == Integer.MAX_VALUE) return "Integer.MAX_VALUE"; else if (val == Integer.MIN_VALUE) return "Integer.MIN_VALUE"; else if (((Integer) value) < 0) return "(" + value + ")"; else return "" + val; } else if (value.getClass().isEnum() || value instanceof Enum) { // java.util.concurrent.TimeUnit is an example where the enum // elements are anonymous inner classes, and then isEnum does // not return true apparently? So we check using instanceof as well. Class<?> clazz = value.getClass(); String className = clazz.getSimpleName(); while (clazz.getEnclosingClass() != null) { String enclosingName = clazz.getEnclosingClass().getSimpleName(); className = enclosingName + "." + className; clazz = clazz.getEnclosingClass(); } // We have to do this here to avoid a double colon in the TimeUnit example if (!className.endsWith(".")) className += "."; try { if (value.getClass().getField(value.toString()) != null) return className + value; else if (((Enum<?>) value).name() != null) return className + ((Enum<?>) value).name(); else return "Enum.valueOf(" + className + "class, \"" + value + "\")"; } catch (Exception e) { if (((Enum<?>) value).name() != null) return className + ((Enum<?>) value).name(); else return "Enum.valueOf(" + className + "class /* " + e + " */, \"" + value + "\")"; // return className + "valueOf(\"" + value + "\")"; } } else if (value.getClass().equals(Boolean.class)) { return value.toString(); } else { // This should not happen assert (false); return value.toString(); } }
From source file:edu.nyu.vida.data_polygamy.scalar_function.Mode.java
@Override public float getResult() { if (count == 0) return Float.NaN; double[] primitiveValues = new double[floatValues.size()]; for (int i = 0; i < floatValues.size(); i++) primitiveValues[i] = floatValues.get(i); return (float) StatUtils.mode(primitiveValues)[0]; }
From source file:edu.nyu.vida.data_polygamy.scalar_function.Median.java
@Override public float getResult() { if (count == 0) return Float.NaN; double[] primitiveValues = new double[floatValues.size()]; for (int i = 0; i < floatValues.size(); i++) primitiveValues[i] = floatValues.get(i); DescriptiveStatistics stats = new DescriptiveStatistics(primitiveValues); return (float) stats.getPercentile(50); }
From source file:Main.java
/** * <p>Returns the maximum value in an array.</p> * // www .j a v a 2s . co 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> * /*from w w w. j av a 2 s . co 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:com.taobao.weex.utils.WXUtils.java
public static float getFloatByViewport(Object value, int viewport) { if (value == null) { return Float.NaN; }/*from w w w. j av a 2 s. co m*/ String temp = value.toString().trim(); if (Constants.Name.AUTO.equals(temp) || Constants.Name.UNDEFINED.equals(temp) || TextUtils.isEmpty(temp)) { WXLogUtils.e("Argument Warning ! value is " + temp + "And default Value:" + Float.NaN); return Float.NaN; } if (temp.endsWith("wx")) { try { return transferWx(temp, viewport); } catch (NumberFormatException e) { WXLogUtils.e("Argument format error! value is " + value, e); } catch (Exception e) { WXLogUtils.e("Argument error! value is " + value, e); } } else if (temp.endsWith("px")) { try { temp = temp.substring(0, temp.indexOf("px")); return Float.parseFloat(temp); } catch (NumberFormatException nfe) { WXLogUtils.e("Argument format error! value is " + value, nfe); } catch (Exception e) { WXLogUtils.e("Argument error! value is " + value, e); } } else { try { return Float.parseFloat(temp); } catch (NumberFormatException nfe) { WXLogUtils.e("Argument format error! value is " + value, nfe); } catch (Exception e) { WXLogUtils.e("Argument error! value is " + value, e); } } return Float.NaN; }
From source file:com.facebook.presto.operator.aggregation.AggregationTestUtils.java
public static void assertAggregation(InternalAggregationFunction function, Object expectedValue, Page page) { BiFunction<Object, Object, Boolean> equalAssertion; if (expectedValue instanceof Double && !expectedValue.equals(Double.NaN)) { equalAssertion = (actual, expected) -> Precision.equals((double) actual, (double) expected, 1e-10); } else if (expectedValue instanceof Float && !expectedValue.equals(Float.NaN)) { equalAssertion = (actual, expected) -> Precision.equals((float) actual, (float) expected, 1e-10f); } else {//w w w .jav a2s . co m equalAssertion = Objects::equals; } assertAggregation(function, equalAssertion, null, page, expectedValue); }
From source file:com.frank.search.solr.repository.query.SolrParameter.java
/** * if method parameter has {@link Boost} use it * //from w w w . j av a2s.c om * @return Float.NaN by default */ public float getBoost() { if (hasBoostAnnotation()) { return getBoostAnnotation().value(); } return Float.NaN; }
From source file:com.tmall.wireless.tangram3.util.Utils.java
public static float getImageRatio(String imageUrl) { if (TextUtils.isEmpty(imageUrl)) return Float.NaN; try {/* ww w. j av a 2 s.c o m*/ Matcher matcher = REGEX_1.matcher(imageUrl); String widthStr; String heightStr; if (matcher.find()) { if (matcher.groupCount() >= 2) { widthStr = matcher.group(1); heightStr = matcher.group(2); if (widthStr.length() < 5 && heightStr.length() < 5) { int urlWidth = Integer.parseInt(widthStr); int urlHeight = Integer.parseInt(heightStr); if (urlWidth == 0 || urlHeight == 0) { return 1; } return (float) urlWidth / urlHeight; } } } else { matcher = REGEX_2.matcher(imageUrl); if (matcher.find()) { if (matcher.groupCount() >= 2) { widthStr = matcher.group(1); heightStr = matcher.group(2); if (widthStr.length() < 5 && heightStr.length() < 5) { int urlWidth = Integer.parseInt(widthStr); int urlHeight = Integer.parseInt(heightStr); if (urlWidth == 0 || urlHeight == 0) { return 1; } return (float) urlWidth / urlHeight; } } } } } catch (Exception e) { e.printStackTrace(); } return Float.NaN; }