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

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

本文整理了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

/**
 * Return the greatest float that compares less than {@code f} consistently
 * with {@link Float#compare}. The only difference with
 * {@link Math#nextDown(float)} is that this method returns {@code -0f} when
 * the argument is {@code +0f}.
 */
public static float nextDown(float f) {
 if (Float.floatToIntBits(f) == 0) { // +0f
  return -0f;
 }
 return Math.nextDown(f);
}

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

/**
 * Return the greatest double that compares less than {@code d} consistently
 * with {@link Double#compare}. The only difference with
 * {@link Math#nextDown(double)} is that this method returns {@code -0d} when
 * the argument is {@code +0d}.
 */
public static double nextDown(double d) {
 if (Double.doubleToLongBits(d) == 0L) { // +0d
  return -0f;
 }
 return Math.nextDown(d);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

@GwtIncompatible("Math::nextUp is not implemented")
  static BigDecimal asDecimal(double number) {
    if (number == NEGATIVE_INFINITY) {
      final BigDecimal result = BigDecimal.valueOf(Math.nextUp(NEGATIVE_INFINITY));
      return result.subtract(INFINITY_DISTANCE.get());
    } else if (number == POSITIVE_INFINITY) {
      final BigDecimal result = BigDecimal.valueOf(Math.nextDown(POSITIVE_INFINITY));
      return result.add(INFINITY_DISTANCE.get());
    } else {
      return BigDecimal.valueOf(number);
    }
  }
}

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

@ScalarOperator(SATURATED_FLOOR_CAST)
@SqlType(StandardTypes.REAL)
public static strictfp long saturatedFloorCastToFloat(@SqlType(StandardTypes.DOUBLE) double value)
{
  float result;
  float minFloat = -1.0f * Float.MAX_VALUE;
  if (value <= minFloat) {
    result = minFloat;
  }
  else if (value >= Float.MAX_VALUE) {
    result = Float.MAX_VALUE;
  }
  else {
    result = (float) value;
    if (result > value) {
      result = Math.nextDown(result);
    }
    checkState(result <= value);
  }
  return floatToRawIntBits(result);
}

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

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

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

@Test
public void testCastToBigint()
{
  assertFunction("cast(37.7E0 as bigint)", BIGINT, 38L);
  assertFunction("cast(-37.7E0 as bigint)", BIGINT, -38L);
  assertFunction("cast(17.1E0 as bigint)", BIGINT, 17L);
  assertFunction("cast(-17.1E0 as bigint)", BIGINT, -17L);
  assertFunction("cast(9.2E18 as bigint)", BIGINT, 9200000000000000000L);
  assertFunction("cast(-9.2E18 as bigint)", BIGINT, -9200000000000000000L);
  assertFunction("cast(2.21E9 as bigint)", BIGINT, 2210000000L);
  assertFunction("cast(-2.21E9 as bigint)", BIGINT, -2210000000L);
  assertFunction("cast(17.5E0 as bigint)", BIGINT, 18L);
  assertFunction("cast(-17.5E0 as bigint)", BIGINT, -18L);
  assertFunction("cast(" + Math.nextDown(0x1.0p63) + " as bigint)", BIGINT, (long) Math.nextDown(0x1.0p63));
  assertInvalidFunction("cast(" + 0x1.0p63 + " as bigint)", INVALID_CAST_ARGUMENT);
  assertInvalidFunction("cast(" + Math.nextUp(0x1.0p63) + " as bigint)", INVALID_CAST_ARGUMENT);
  assertInvalidFunction("cast(" + Math.nextDown(-0x1.0p63) + " as bigint)", INVALID_CAST_ARGUMENT);
  assertFunction("cast(" + -0x1.0p63 + " as bigint)", BIGINT, (long) -0x1.0p63);
  assertFunction("cast(" + Math.nextUp(-0x1.0p63) + " as bigint)", BIGINT, (long) Math.nextUp(-0x1.0p63));
  assertInvalidFunction("cast(9.3E18 as bigint)", INVALID_CAST_ARGUMENT);
  assertInvalidFunction("cast(-9.3E18 as bigint)", INVALID_CAST_ARGUMENT);
  assertInvalidFunction("cast(infinity() as bigint)", INVALID_CAST_ARGUMENT);
  assertInvalidFunction("cast(-infinity() as bigint)", INVALID_CAST_ARGUMENT);
  assertInvalidFunction("cast(nan() as bigint)", INVALID_CAST_ARGUMENT);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

相关文章