List of usage examples for java.lang Float isInfinite
public static boolean isInfinite(float v)
From source file:org.eclipse.january.dataset.DatasetUtils.java
/** * Removes NaNs and infinities from floating point datasets. * All other dataset types are ignored.// ww w .j a va2 s. c om * * @param a dataset * @param value replacement value */ public static void removeNansAndInfinities(Dataset a, final Number value) { if (a instanceof DoubleDataset) { final double dvalue = DTypeUtils.toReal(value); final DoubleDataset set = (DoubleDataset) a; final IndexIterator it = set.getIterator(); final double[] data = set.getData(); while (it.hasNext()) { double x = data[it.index]; if (Double.isNaN(x) || Double.isInfinite(x)) data[it.index] = dvalue; } } else if (a instanceof FloatDataset) { final float fvalue = (float) DTypeUtils.toReal(value); final FloatDataset set = (FloatDataset) a; final IndexIterator it = set.getIterator(); final float[] data = set.getData(); while (it.hasNext()) { float x = data[it.index]; if (Float.isNaN(x) || Float.isInfinite(x)) data[it.index] = fvalue; } } else if (a instanceof CompoundDoubleDataset) { final double dvalue = DTypeUtils.toReal(value); final CompoundDoubleDataset set = (CompoundDoubleDataset) a; final int is = set.getElementsPerItem(); final IndexIterator it = set.getIterator(); final double[] data = set.getData(); while (it.hasNext()) { for (int j = 0; j < is; j++) { double x = data[it.index + j]; if (Double.isNaN(x) || Double.isInfinite(x)) data[it.index + j] = dvalue; } } } else if (a instanceof CompoundFloatDataset) { final float fvalue = (float) DTypeUtils.toReal(value); final CompoundFloatDataset set = (CompoundFloatDataset) a; final int is = set.getElementsPerItem(); final IndexIterator it = set.getIterator(); final float[] data = set.getData(); while (it.hasNext()) { for (int j = 0; j < is; j++) { float x = data[it.index + j]; if (Float.isNaN(x) || Float.isInfinite(x)) data[it.index + j] = fvalue; } } } }
From source file:org.eclipse.january.dataset.DatasetUtils.java
/** * Make floating point datasets contain only finite values. Infinities and NaNs are replaced * by +/- MAX_VALUE and 0, respectively. * All other dataset types are ignored./* ww w. j a va 2 s . com*/ * * @param a dataset */ public static void makeFinite(Dataset a) { if (a instanceof DoubleDataset) { final DoubleDataset set = (DoubleDataset) a; final IndexIterator it = set.getIterator(); final double[] data = set.getData(); while (it.hasNext()) { final double x = data[it.index]; if (Double.isNaN(x)) data[it.index] = 0; else if (Double.isInfinite(x)) data[it.index] = x > 0 ? Double.MAX_VALUE : -Double.MAX_VALUE; } } else if (a instanceof FloatDataset) { final FloatDataset set = (FloatDataset) a; final IndexIterator it = set.getIterator(); final float[] data = set.getData(); while (it.hasNext()) { final float x = data[it.index]; if (Float.isNaN(x)) data[it.index] = 0; else if (Float.isInfinite(x)) data[it.index] = x > 0 ? Float.MAX_VALUE : -Float.MAX_VALUE; } } else if (a instanceof CompoundDoubleDataset) { final CompoundDoubleDataset set = (CompoundDoubleDataset) a; final int is = set.getElementsPerItem(); final IndexIterator it = set.getIterator(); final double[] data = set.getData(); while (it.hasNext()) { for (int j = 0; j < is; j++) { final double x = data[it.index + j]; if (Double.isNaN(x)) data[it.index + j] = 0; else if (Double.isInfinite(x)) data[it.index + j] = x > 0 ? Double.MAX_VALUE : -Double.MAX_VALUE; } } } else if (a instanceof CompoundFloatDataset) { final CompoundFloatDataset set = (CompoundFloatDataset) a; final int is = set.getElementsPerItem(); final IndexIterator it = set.getIterator(); final float[] data = set.getData(); while (it.hasNext()) { for (int j = 0; j < is; j++) { final float x = data[it.index + j]; if (Float.isNaN(x)) data[it.index + j] = 0; else if (Float.isInfinite(x)) data[it.index + j] = x > 0 ? Float.MAX_VALUE : -Float.MAX_VALUE; } } } }
From source file:net.pms.util.Rational.java
/** * Compares this {@link Rational} by value with any class implementing * {@link Number}./*from ww w . java2s . c o m*/ * <p> * This method is provided in preference to individual methods for each of * the six boolean comparison operators ({@literal <}, ==, {@literal >}, * {@literal >=}, !=, {@literal <=}). The suggested idiom for performing * these comparisons is: {@code (x.compareTo(y)} <<i>op</i>> * {@code 0)}, where <<i>op</i>> is one of the six comparison * operators. * <p> * <b>Note:</b> {@code NaN} can't be compared by value and is considered * greater than anything but itself as defined for {@link Double}. * * @param number the {@link Number} to which this {@link Rational}'s value * is to be compared. * @return A negative integer, zero, or a positive integer as this * {@link Rational} is numerically less than, equal to, or greater * than {@code number}. */ public int compareTo(@Nonnull Number number) { // Establish special cases boolean numberIsNaN; boolean numberIsInfinite; int numberSignum; if (number instanceof Rational) { numberIsNaN = Rational.isNaN((Rational) number); numberIsInfinite = Rational.isInfinite((Rational) number); numberSignum = ((Rational) number).numerator.signum(); } else if (number instanceof Float) { numberIsNaN = Float.isNaN(number.floatValue()); numberIsInfinite = Float.isInfinite(number.floatValue()); numberSignum = (int) Math.signum(number.floatValue()); } else if (number instanceof Double) { numberIsNaN = Double.isNaN(number.doubleValue()); numberIsInfinite = Double.isInfinite(number.doubleValue()); numberSignum = (int) Math.signum(number.doubleValue()); } else { numberIsNaN = false; numberIsInfinite = false; long l = number.longValue(); numberSignum = l == 0 ? 0 : l > 0 ? 1 : -1; } // NaN comparison is done according to the rules for Double. if (isNaN()) { return numberIsNaN ? 0 : 1; } if (numberIsNaN) { return -1; } if (isInfinite()) { if (numberIsInfinite) { return signum() - numberSignum; } return this.signum(); } if (numberIsInfinite) { return -numberSignum; } // List known integer types for faster and more accurate comparison if (number instanceof BigInteger) { if (isInteger()) { return bigIntegerValue().compareTo((BigInteger) number); } return bigDecimalValue(2, RoundingMode.HALF_EVEN).compareTo(new BigDecimal((BigInteger) number)); } if (number instanceof AtomicInteger || number instanceof AtomicLong || number instanceof Byte || number instanceof Integer || number instanceof Long || number instanceof Short) { if (isInteger()) { return bigIntegerValue().compareTo(BigInteger.valueOf(number.longValue())); } return bigDecimalValue(2, RoundingMode.HALF_EVEN).compareTo(new BigDecimal(number.longValue())); } if (number instanceof BigDecimal) { Rational other = valueOf((BigDecimal) number); return compareTo(other); } return bigDecimalValue().compareTo(new BigDecimal(number.doubleValue())); }
From source file:com.actelion.research.table.view.JVisualization.java
/** * Formats a numerical value for displaying it. * This includes proper rounding and potential de-logarithmization of the original value. * @param value is the logarithm, if the column is in logarithmic view mode * @param column the column this value refers to * @return//from w w w . j a v a 2 s .c o m */ protected String formatValue(float value, int column) { if (mTableModel.isLogarithmicViewMode(column) && !Float.isNaN(value) && !Float.isInfinite(value)) value = (float) Math.pow(10, value); return DoubleFormat.toString(value); }