java.lang.Math.nextDown()方法的使用及代码示例

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

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

Math.nextDown介绍

暂无

代码示例

代码示例来源:origin: org.apache.lucene/lucene-core

  1. /**
  2. * Return the greatest float that compares less than {@code f} consistently
  3. * with {@link Float#compare}. The only difference with
  4. * {@link Math#nextDown(float)} is that this method returns {@code -0f} when
  5. * the argument is {@code +0f}.
  6. */
  7. public static float nextDown(float f) {
  8. if (Float.floatToIntBits(f) == 0) { // +0f
  9. return -0f;
  10. }
  11. return Math.nextDown(f);
  12. }

代码示例来源:origin: org.apache.lucene/lucene-core

  1. /**
  2. * Return the greatest double that compares less than {@code d} consistently
  3. * with {@link Double#compare}. The only difference with
  4. * {@link Math#nextDown(double)} is that this method returns {@code -0d} when
  5. * the argument is {@code +0d}.
  6. */
  7. public static double nextDown(double d) {
  8. if (Double.doubleToLongBits(d) == 0L) { // +0d
  9. return -0f;
  10. }
  11. return Math.nextDown(d);
  12. }

代码示例来源:origin: google/error-prone

  1. @Override
  2. Float nextNumber(Number actual) {
  3. float number = actual.floatValue();
  4. return Math.min(Math.nextUp(number) - number, number - Math.nextDown(number));
  5. }

代码示例来源:origin: google/error-prone

  1. @Override
  2. Double nextNumber(Number actual) {
  3. double number = actual.doubleValue();
  4. return Math.min(Math.nextUp(number) - number, number - Math.nextDown(number));
  5. }

代码示例来源:origin: org.apache.lucene/lucene-core

  1. /**
  2. * Quantizes double (64 bit) latitude into 32 bits (rounding down: in the direction of -90)
  3. * @param latitude latitude value: must be within standard +/-90 coordinate bounds.
  4. * @return encoded value as a 32-bit {@code int}
  5. * @throws IllegalArgumentException if latitude is out of bounds
  6. */
  7. public static int encodeLatitude(double latitude) {
  8. checkLatitude(latitude);
  9. // the maximum possible value cannot be encoded without overflow
  10. if (latitude == 90.0D) {
  11. latitude = Math.nextDown(latitude);
  12. }
  13. return (int) Math.floor(latitude / LAT_DECODE);
  14. }

代码示例来源:origin: org.apache.lucene/lucene-core

  1. /**
  2. * Quantizes double (64 bit) longitude into 32 bits (rounding down: in the direction of -180)
  3. * @param longitude longitude value: must be within standard +/-180 coordinate bounds.
  4. * @return encoded value as a 32-bit {@code int}
  5. * @throws IllegalArgumentException if longitude is out of bounds
  6. */
  7. public static int encodeLongitude(double longitude) {
  8. checkLongitude(longitude);
  9. // the maximum possible value cannot be encoded without overflow
  10. if (longitude == 180.0D) {
  11. longitude = Math.nextDown(longitude);
  12. }
  13. return (int) Math.floor(longitude / LON_DECODE);
  14. }

代码示例来源:origin: org.apache.lucene/lucene-core

  1. /**
  2. * Quantizes double (64 bit) longitude into 32 bits (rounding up: in the direction of +180)
  3. * @param longitude longitude value: must be within standard +/-180 coordinate bounds.
  4. * @return encoded value as a 32-bit {@code int}
  5. * @throws IllegalArgumentException if longitude is out of bounds
  6. */
  7. public static int encodeLongitudeCeil(double longitude) {
  8. GeoUtils.checkLongitude(longitude);
  9. // the maximum possible value cannot be encoded without overflow
  10. if (longitude == 180.0D) {
  11. longitude = Math.nextDown(longitude);
  12. }
  13. return (int) Math.ceil(longitude / LON_DECODE);
  14. }

代码示例来源:origin: org.apache.lucene/lucene-core

  1. /**
  2. * Quantizes double (64 bit) latitude into 32 bits (rounding up: in the direction of +90)
  3. * @param latitude latitude value: must be within standard +/-90 coordinate bounds.
  4. * @return encoded value as a 32-bit {@code int}
  5. * @throws IllegalArgumentException if latitude is out of bounds
  6. */
  7. public static int encodeLatitudeCeil(double latitude) {
  8. GeoUtils.checkLatitude(latitude);
  9. // the maximum possible value cannot be encoded without overflow
  10. if (latitude == 90.0D) {
  11. latitude = Math.nextDown(latitude);
  12. }
  13. return (int) Math.ceil(latitude / LAT_DECODE);
  14. }

代码示例来源:origin: vavr-io/vavr

  1. @GwtIncompatible("Math::nextUp is not implemented")
  2. static BigDecimal asDecimal(double number) {
  3. if (number == NEGATIVE_INFINITY) {
  4. final BigDecimal result = BigDecimal.valueOf(Math.nextUp(NEGATIVE_INFINITY));
  5. return result.subtract(INFINITY_DISTANCE.get());
  6. } else if (number == POSITIVE_INFINITY) {
  7. final BigDecimal result = BigDecimal.valueOf(Math.nextDown(POSITIVE_INFINITY));
  8. return result.add(INFINITY_DISTANCE.get());
  9. } else {
  10. return BigDecimal.valueOf(number);
  11. }
  12. }
  13. }

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

  1. @ScalarOperator(SATURATED_FLOOR_CAST)
  2. @SqlType(StandardTypes.REAL)
  3. public static strictfp long saturatedFloorCastToFloat(@SqlType(StandardTypes.DOUBLE) double value)
  4. {
  5. float result;
  6. float minFloat = -1.0f * Float.MAX_VALUE;
  7. if (value <= minFloat) {
  8. result = minFloat;
  9. }
  10. else if (value >= Float.MAX_VALUE) {
  11. result = Float.MAX_VALUE;
  12. }
  13. else {
  14. result = (float) value;
  15. if (result > value) {
  16. result = Math.nextDown(result);
  17. }
  18. checkState(result <= value);
  19. }
  20. return floatToRawIntBits(result);
  21. }

代码示例来源:origin: vavr-io/vavr

  1. @GwtIncompatible
  2. static Iterator<Double> rangeClosedBy(double from, double toInclusive, double step) {
  3. if (from == toInclusive) {
  4. return of(from);
  5. }
  6. final double toExclusive = (step > 0) ? Math.nextUp(toInclusive) : Math.nextDown(toInclusive);
  7. return rangeBy(from, toExclusive, step);
  8. }

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

  1. @Test
  2. public void testCastToBigint()
  3. {
  4. assertFunction("cast(37.7E0 as bigint)", BIGINT, 38L);
  5. assertFunction("cast(-37.7E0 as bigint)", BIGINT, -38L);
  6. assertFunction("cast(17.1E0 as bigint)", BIGINT, 17L);
  7. assertFunction("cast(-17.1E0 as bigint)", BIGINT, -17L);
  8. assertFunction("cast(9.2E18 as bigint)", BIGINT, 9200000000000000000L);
  9. assertFunction("cast(-9.2E18 as bigint)", BIGINT, -9200000000000000000L);
  10. assertFunction("cast(2.21E9 as bigint)", BIGINT, 2210000000L);
  11. assertFunction("cast(-2.21E9 as bigint)", BIGINT, -2210000000L);
  12. assertFunction("cast(17.5E0 as bigint)", BIGINT, 18L);
  13. assertFunction("cast(-17.5E0 as bigint)", BIGINT, -18L);
  14. assertFunction("cast(" + Math.nextDown(0x1.0p63) + " as bigint)", BIGINT, (long) Math.nextDown(0x1.0p63));
  15. assertInvalidFunction("cast(" + 0x1.0p63 + " as bigint)", INVALID_CAST_ARGUMENT);
  16. assertInvalidFunction("cast(" + Math.nextUp(0x1.0p63) + " as bigint)", INVALID_CAST_ARGUMENT);
  17. assertInvalidFunction("cast(" + Math.nextDown(-0x1.0p63) + " as bigint)", INVALID_CAST_ARGUMENT);
  18. assertFunction("cast(" + -0x1.0p63 + " as bigint)", BIGINT, (long) -0x1.0p63);
  19. assertFunction("cast(" + Math.nextUp(-0x1.0p63) + " as bigint)", BIGINT, (long) Math.nextUp(-0x1.0p63));
  20. assertInvalidFunction("cast(9.3E18 as bigint)", INVALID_CAST_ARGUMENT);
  21. assertInvalidFunction("cast(-9.3E18 as bigint)", INVALID_CAST_ARGUMENT);
  22. assertInvalidFunction("cast(infinity() as bigint)", INVALID_CAST_ARGUMENT);
  23. assertInvalidFunction("cast(-infinity() as bigint)", INVALID_CAST_ARGUMENT);
  24. assertInvalidFunction("cast(nan() as bigint)", INVALID_CAST_ARGUMENT);
  25. }

代码示例来源:origin: org.elasticsearch/elasticsearch

  1. @Override
  2. public Query containsQuery(String field, Object from, Object to, boolean includeFrom, boolean includeTo) {
  3. return DoubleRange.newContainsQuery(field,
  4. new double[] {includeFrom ? (Double)from : Math.nextUp((Double)from)},
  5. new double[] {includeTo ? (Double)to : Math.nextDown((Double)to)});
  6. }
  7. @Override

代码示例来源:origin: org.elasticsearch/elasticsearch

  1. @Override
  2. public Query containsQuery(String field, Object from, Object to, boolean includeFrom, boolean includeTo) {
  3. return FloatRange.newContainsQuery(field,
  4. new float[] {includeFrom ? (Float)from : Math.nextUp((Float)from)},
  5. new float[] {includeTo ? (Float)to : Math.nextDown((Float)to)});
  6. }
  7. @Override

代码示例来源:origin: org.elasticsearch/elasticsearch

  1. @Override
  2. public Query withinQuery(String field, Object from, Object to, boolean includeFrom, boolean includeTo) {
  3. return DoubleRange.newWithinQuery(field,
  4. new double[] {includeFrom ? (Double)from : Math.nextUp((Double)from)},
  5. new double[] {includeTo ? (Double)to : Math.nextDown((Double)to)});
  6. }
  7. @Override

代码示例来源:origin: org.elasticsearch/elasticsearch

  1. @Override
  2. public Query intersectsQuery(String field, Object from, Object to, boolean includeFrom, boolean includeTo) {
  3. return DoubleRange.newIntersectsQuery(field,
  4. new double[] {includeFrom ? (Double)from : Math.nextUp((Double)from)},
  5. new double[] {includeTo ? (Double)to : Math.nextDown((Double)to)});
  6. }
  7. },

代码示例来源:origin: org.elasticsearch/elasticsearch

  1. @Override
  2. public Query withinQuery(String field, Object from, Object to, boolean includeFrom, boolean includeTo) {
  3. return FloatRange.newWithinQuery(field,
  4. new float[] {includeFrom ? (Float)from : Math.nextUp((Float)from)},
  5. new float[] {includeTo ? (Float)to : Math.nextDown((Float)to)});
  6. }
  7. @Override

代码示例来源:origin: org.elasticsearch/elasticsearch

  1. @Override
  2. public Query intersectsQuery(String field, Object from, Object to, boolean includeFrom, boolean includeTo) {
  3. return FloatRange.newIntersectsQuery(field,
  4. new float[] {includeFrom ? (Float)from : Math.nextUp((Float)from)},
  5. new float[] {includeTo ? (Float)to : Math.nextDown((Float)to)});
  6. }
  7. },

代码示例来源:origin: rnewson/couchdb-lucene

  1. @Override
  2. public Query toRangeQuery(final String name, final String lower, final String upper,
  3. final boolean lowerInclusive, final boolean upperInclusive) {
  4. return DoublePoint.newRangeQuery(name,
  5. lowerInclusive ? toDouble(lower) : Math.nextUp(toDouble(lower)),
  6. upperInclusive ? toDouble(upper) : Math.nextDown(toDouble(upper)));
  7. }

代码示例来源:origin: rnewson/couchdb-lucene

  1. @Override
  2. public Query toRangeQuery(final String name, final String lower, final String upper,
  3. final boolean lowerInclusive, final boolean upperInclusive) {
  4. return FloatPoint.newRangeQuery(name,
  5. lowerInclusive ? toFloat(lower) : Math.nextUp(toFloat(lower)),
  6. upperInclusive ? toFloat(upper) : Math.nextDown(toFloat(upper)));
  7. }

相关文章