/** Returns whether any of the values in {@code dataset} are {@code NaN}. */ private static boolean containsNaN(double... dataset) { for (double value : dataset) { if (Double.isNaN(value)) { return true; } } return false; }
// 1. static method if (Double.isNaN(doubleValue)) { ... } // 2. object's method if (doubleObject.isNan()) { ... }
/** * Checks whether the double value is the special NaN value. * * @return true if NaN */ public boolean isNaN() { return Double.isNaN(value); }
/** Returns its argument if it is non-negative, zero if it is negative. */ static double ensureNonNegative(double value) { checkArgument(!isNaN(value)); if (value > 0.0) { return value; } else { return 0.0; } }
private PlanNodeStatsEstimate(double outputRowCount, PMap<Symbol, SymbolStatsEstimate> symbolStatistics) { checkArgument(isNaN(outputRowCount) || outputRowCount >= 0, "outputRowCount cannot be negative"); this.outputRowCount = outputRowCount; this.symbolStatistics = symbolStatistics; }
public void addValue(double value) { nonNullValueCount++; if (Double.isNaN(value)) { hasNan = true; } else { minimum = Math.min(value, minimum); maximum = Math.max(value, maximum); } }
public static Estimate of(double value) { if (isNaN(value)) { throw new IllegalArgumentException("value is NaN"); } if (isInfinite(value)) { throw new IllegalArgumentException("value is infinite"); } return new Estimate(value); }
@Override protected Number getNormalizedValue() { if (value.isNaN() || value.isInfinite()) { return value; } return new BigDecimal(getValue().doubleValue()).round(new MathContext(precision)).doubleValue(); } }
@Test public void testGroupByNanMap() { MaterializedResult actual = computeActual("SELECT MAP_KEYS(x)[1] FROM (VALUES MAP(ARRAY[nan()], ARRAY[ARRAY[1]]), MAP(ARRAY[nan()], ARRAY[ARRAY[2]])) t(x) GROUP BY 1"); assertTrue(Double.isNaN((Double) actual.getOnlyValue())); }
/** * Finish building an instance with the given slope, i.e. the rate of change of {@code y} with * respect to {@code x}. The slope must not be {@code NaN}. It may be infinite, in which case * the transformation is vertical. (If it is zero, the transformation is horizontal.) */ public LinearTransformation withSlope(double slope) { checkArgument(!Double.isNaN(slope)); if (isFinite(slope)) { double yIntercept = y1 - x1 * slope; return new RegularLinearTransformation(slope, yIntercept); } else { return new VerticalLinearTransformation(x1); } } }
public void testFuzzyEqualsZeroTolerance() { // make sure we test -0 tolerance for (double zero : Doubles.asList(0.0, -0.0)) { for (double a : ALL_DOUBLE_CANDIDATES) { for (double b : ALL_DOUBLE_CANDIDATES) { assertEquals( a == b || (Double.isNaN(a) && Double.isNaN(b)), DoubleMath.fuzzyEquals(a, b, zero)); } } } }
public void testIsFinite() { for (double value : NUMBERS) { assertEquals(!(Double.isNaN(value) || Double.isInfinite(value)), Doubles.isFinite(value)); } }
public void testLog2Negative() { for (double d : POSITIVE_FINITE_DOUBLE_CANDIDATES) { assertTrue(Double.isNaN(DoubleMath.log2(-d))); } }
private static void assertEquivalent(double actual, double expected) { if (expected == POSITIVE_INFINITY) { assertThat(actual).isPositiveInfinity(); } else if (expected == NEGATIVE_INFINITY) { assertThat(actual).isNegativeInfinity(); } else if (Double.isNaN(expected)) { assertThat(actual).isNaN(); } else { assertThat(actual).isWithin(ALLOWED_ERROR).of(expected); } } }
public SymbolStatsAssertion distinctValuesCountUnknown() { assertTrue(isNaN(statistics.getDistinctValuesCount()), "expected unknown distinctValuesCount but got " + statistics.getDistinctValuesCount()); return this; }
public SymbolStatsAssertion dataSizeUnknown() { assertTrue(isNaN(statistics.getAverageRowSize()), "expected unknown dataSize but got " + statistics.getAverageRowSize()); return this; }
@GwtIncompatible // DoubleMath.isPowerOfTwo, DoubleMath.log2(double, RoundingMode), StrictMath public void testIsPowerOfTwo() { for (double x : ALL_DOUBLE_CANDIDATES) { boolean expected = x > 0 && !Double.isInfinite(x) && !Double.isNaN(x) && StrictMath.pow(2.0, DoubleMath.log2(x, FLOOR)) == x; assertEquals(expected, DoubleMath.isPowerOfTwo(x)); } }
public void testMin() { assertEquals(LEAST, Doubles.min(LEAST)); assertEquals(GREATEST, Doubles.min(GREATEST)); assertEquals( (double) 0, Doubles.min( (double) 8, (double) 6, (double) 7, (double) 5, (double) 3, (double) 0, (double) 9)); assertEquals(-0.0, Doubles.min(-0.0, 0.0)); assertEquals(-0.0, Doubles.min(0.0, -0.0)); assertEquals(LEAST, Doubles.min(NUMBERS)); assertTrue(Double.isNaN(Doubles.min(VALUES))); }
public void testMax() { assertEquals(LEAST, Doubles.max(LEAST)); assertEquals(GREATEST, Doubles.max(GREATEST)); assertEquals( (double) 9, Doubles.max( (double) 8, (double) 6, (double) 7, (double) 5, (double) 3, (double) 0, (double) 9)); assertEquals(0.0, Doubles.max(-0.0, 0.0)); assertEquals(0.0, Doubles.max(0.0, -0.0)); assertEquals(GREATEST, Doubles.max(NUMBERS)); assertTrue(Double.isNaN(Doubles.max(VALUES))); }