java.lang.Float.compare()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(209)

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

Float.compare介绍

[英]Compares the two specified float values. There are two special cases:

  • Float.NaN is equal to Float.NaN and it is greater than any other float value, including Float.POSITIVE_INFINITY;
  • +0.0f is greater than -0.0f
    [中]比较两个指定的浮点值。有两种特殊情况:
    *浮动。NaN等于Float。NaN,它大于任何其他浮点值,包括浮点值。正无穷大;
    *+0.0f大于-0.0f

代码示例

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

/**
 * Compares the two specified {@code float} values using {@link Float#compare(float, float)}. You
 * may prefer to invoke that method directly; this method exists only for consistency with the
 * other utilities in this package.
 *
 * <p><b>Note:</b> this method simply delegates to the JDK method {@link Float#compare}. It is
 * provided for consistency with the other primitive types, whose compare methods were not added
 * to the JDK until JDK 7.
 *
 * @param a the first {@code float} to compare
 * @param b the second {@code float} to compare
 * @return the result of invoking {@link Float#compare(float, float)}
 */
public static int compare(float a, float b) {
 return Float.compare(a, b);
}

代码示例来源:origin: hankcs/HanLP

public int compare(WordInfo o1, WordInfo o2)
  {
    return Float.compare(o1.p, o2.p);
  }
});

代码示例来源:origin: hankcs/HanLP

@Override
  public int compareTo(State o)
  {
    return Float.compare(cost, o.cost);
  }
}

代码示例来源:origin: hankcs/HanLP

@Override
  public int compare(FeatureSortItem o1, FeatureSortItem o2)
  {
    return Float.compare(o1.total, o2.total);
  }
});

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

/**
 * Compares this mutable to another in ascending order.
 *
 * @param other  the other mutable to compare to, not null
 * @return negative if this is less, zero if equal, positive if greater
 */
@Override
public int compareTo(final MutableFloat other) {
  return Float.compare(this.value, other.value);
}

代码示例来源:origin: redisson/redisson

/**
 * Finds the first occurrence of value in <code>float</code> array.
 */
public static int indexOf(float[] array, float value) {
  for (int i = 0; i < array.length; i++) {
    if (Float.compare(array[i], value) == 0) {
      return i;
    }
  }
  return -1;
}
/**

代码示例来源:origin: redisson/redisson

/**
 * Finds the first occurrence in <code>float</code> array from specified given position and upto given length.
 */
public static int indexOf(float[] array, float value, int startIndex, int endIndex) {
  for (int i = startIndex; i < endIndex; i++) {
    if (Float.compare(array[i], value) == 0) {
      return i;
    }
  }
  return -1;
}

代码示例来源:origin: redisson/redisson

/**
 * Compares value of two same instances.
 */
public int compareTo(MutableFloat other) {
  return Float.compare(value, other.value);
}

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

@Override
public boolean equals(Object o)
{
  if (o == this) return true;
  if (o == null) return false;
  if (o instanceof FloatNode) {
    // We must account for NaNs: NaN does not equal NaN, therefore we have
    // to use Double.compare().
    final float otherValue = ((FloatNode) o)._value;
    return Float.compare(_value, otherValue) == 0;
  }
  return false;
}

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

@Override
public int compare(float[] left, float[] right) {
 int minLength = Math.min(left.length, right.length);
 for (int i = 0; i < minLength; i++) {
  int result = Float.compare(left[i], right[i]);
  if (result != 0) {
   return result;
  }
 }
 return left.length - right.length;
}

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

@Override
public int compare(float[] left, float[] right) {
 int minLength = Math.min(left.length, right.length);
 for (int i = 0; i < minLength; i++) {
  int result = Float.compare(left[i], right[i]);
  if (result != 0) {
   return result;
  }
 }
 return left.length - right.length;
}

代码示例来源:origin: junit-team/junit4

private static boolean floatIsDifferent(float f1, float f2, float delta) {
  if (Float.compare(f1, f2) == 0) {
    return false;
  }
  if ((Math.abs(f1 - f2) <= delta)) {
    return false;
  }
  return true;
}

代码示例来源:origin: apache/incubator-druid

@Override
 public int compare(Object o, Object o1)
 {
  return Float.compare(((Number) o).floatValue(), ((Number) o1).floatValue());
 }
}.nullsFirst();

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

@Override
public ComparisonChain compare(float left, float right) {
 return classify(Float.compare(left, right));
}

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

@Override
public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
  // WARNING: the correctness of InCodeGenerator is dependent on the implementation of this
  // function being the equivalence of internal long representation.
  float leftValue = intBitsToFloat(leftBlock.getInt(leftPosition, 0));
  float rightValue = intBitsToFloat(rightBlock.getInt(rightPosition, 0));
  return Float.compare(leftValue, rightValue);
}

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

@Override
public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition)
{
  // WARNING: the correctness of InCodeGenerator is dependent on the implementation of this
  // function being the equivalence of internal long representation.
  float leftValue = intBitsToFloat(leftBlock.getInt(leftPosition, 0));
  float rightValue = intBitsToFloat(rightBlock.getInt(rightPosition, 0));
  return Float.compare(leftValue, rightValue);
}

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

private static void testSortDescending(float[] input, float[] expectedOutput) {
 input = Arrays.copyOf(input, input.length);
 Floats.sortDescending(input);
 // GWT's Arrays.equals doesn't appear to handle NaN correctly, so test each element individually
 for (int i = 0; i < input.length; i++) {
  assertEquals(0, Float.compare(expectedOutput[i], input[i]));
 }
}

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

private static void testSortDescending(
  float[] input, int fromIndex, int toIndex, float[] expectedOutput) {
 input = Arrays.copyOf(input, input.length);
 Floats.sortDescending(input, fromIndex, toIndex);
 // GWT's Arrays.equals doesn't appear to handle NaN correctly, so test each element individually
 for (int i = 0; i < input.length; i++) {
  assertEquals(0, Float.compare(expectedOutput[i], input[i]));
 }
}

代码示例来源:origin: apache/incubator-druid

@Override
 public int compare(Row o1, Row o2)
 {
  int value = Float.compare(o1.getMetric("rows").floatValue(), o2.getMetric("rows").floatValue());
  if (value != 0) {
   return value;
  }
  return idxComparator.compare(o1, o2);
 }
};

代码示例来源:origin: apache/incubator-druid

@Override
 public int compare(Row o1, Row o2)
 {
  return Float.compare(o1.getMetric("idx").floatValue(), o2.getMetric("idx").floatValue());
 }
};

相关文章