java.lang.Double.isNaN()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(353)

本文整理了Java中java.lang.Double.isNaN()方法的一些代码示例,展示了Double.isNaN()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Double.isNaN()方法的具体详情如下:
包路径:java.lang.Double
类名称:Double
方法名:isNaN

Double.isNaN介绍

[英]Indicates whether this object is a Not-a-Number (NaN) value.
[中]指示此对象是否为*非数字(NaN)*值。

代码示例

代码示例来源:origin: google/guava

/** 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;
}

代码示例来源:origin: stackoverflow.com

// 1. static method
if (Double.isNaN(doubleValue)) {
  ...
}
// 2. object's method
if (doubleObject.isNan()) {
  ...
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Checks whether the double value is the special NaN value.
 *
 * @return true if NaN
 */
public boolean isNaN() {
  return Double.isNaN(value);
}

代码示例来源:origin: google/guava

/** 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;
 }
}

代码示例来源:origin: prestodb/presto

private PlanNodeStatsEstimate(double outputRowCount, PMap<Symbol, SymbolStatsEstimate> symbolStatistics)
{
  checkArgument(isNaN(outputRowCount) || outputRowCount >= 0, "outputRowCount cannot be negative");
  this.outputRowCount = outputRowCount;
  this.symbolStatistics = symbolStatistics;
}

代码示例来源:origin: prestodb/presto

public void addValue(double value)
{
  nonNullValueCount++;
  if (Double.isNaN(value)) {
    hasNan = true;
  }
  else {
    minimum = Math.min(value, minimum);
    maximum = Math.max(value, maximum);
  }
}

代码示例来源:origin: prestodb/presto

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);
}

代码示例来源:origin: prestodb/presto

@Override
  protected Number getNormalizedValue()
  {
    if (value.isNaN() || value.isInfinite()) {
      return value;
    }
    return new BigDecimal(getValue().doubleValue()).round(new MathContext(precision)).doubleValue();
  }
}

代码示例来源:origin: prestodb/presto

@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()));
}

代码示例来源:origin: google/guava

/**
  * 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);
  }
 }
}

代码示例来源:origin: google/guava

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));
   }
  }
 }
}

代码示例来源:origin: google/guava

public void testIsFinite() {
 for (double value : NUMBERS) {
  assertEquals(!(Double.isNaN(value) || Double.isInfinite(value)), Doubles.isFinite(value));
 }
}

代码示例来源:origin: google/guava

public void testLog2Negative() {
 for (double d : POSITIVE_FINITE_DOUBLE_CANDIDATES) {
  assertTrue(Double.isNaN(DoubleMath.log2(-d)));
 }
}

代码示例来源:origin: google/guava

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);
  }
 }
}

代码示例来源:origin: prestodb/presto

public SymbolStatsAssertion distinctValuesCountUnknown()
{
  assertTrue(isNaN(statistics.getDistinctValuesCount()), "expected unknown distinctValuesCount but got " + statistics.getDistinctValuesCount());
  return this;
}

代码示例来源:origin: prestodb/presto

public SymbolStatsAssertion dataSizeUnknown()
{
  assertTrue(isNaN(statistics.getAverageRowSize()), "expected unknown dataSize but got " + statistics.getAverageRowSize());
  return this;
}

代码示例来源:origin: google/guava

public void testLog2NaNInfinity() {
 assertEquals(Double.POSITIVE_INFINITY, DoubleMath.log2(Double.POSITIVE_INFINITY));
 assertTrue(Double.isNaN(DoubleMath.log2(Double.NEGATIVE_INFINITY)));
 assertTrue(Double.isNaN(DoubleMath.log2(Double.NaN)));
}

代码示例来源:origin: google/guava

@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));
 }
}

代码示例来源:origin: google/guava

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)));
}

代码示例来源:origin: google/guava

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)));
}

相关文章