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

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

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

Math.nextAfter介绍

[英]Returns the next double after start in the given direction.
[中]返回给定方向上开始后的下一个双精度。

代码示例

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

  1. /**
  2. * Returns the next float after {@code start} in the given {@code direction}.
  3. * @since 1.6
  4. */
  5. public static float nextAfter(float start, double direction) {
  6. return Math.nextAfter(start, direction);
  7. }

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

  1. @Override
  2. protected ExprEval eval(double x, double y)
  3. {
  4. return ExprEval.of(Math.nextAfter(x, y));
  5. }
  6. }

代码示例来源:origin: kiegroup/optaplanner

  1. @Override
  2. public Double next() {
  3. if (to == from) {
  4. throw new NoSuchElementException();
  5. }
  6. double diff = to - from;
  7. double next = from + diff * workingRandom.nextDouble();
  8. if (next >= to) {
  9. // Rounding error occurred
  10. next = Math.nextAfter(next, Double.NEGATIVE_INFINITY);
  11. }
  12. return next;
  13. }

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

  1. Math.min(Math.max(Math.nextAfter(percentile, Double.NEGATIVE_INFINITY), 0.0D), 100.0D);

代码示例来源:origin: kiegroup/optaplanner

  1. @Test
  2. public void cornerCase() {
  3. Random random = mock(Random.class);
  4. NearbyRandom nearbyRandom = new LinearDistributionNearbyRandom(100);
  5. when(random.nextDouble()).thenReturn(Math.nextAfter(1.0, Double.NEGATIVE_INFINITY));
  6. assertEquals(9, nearbyRandom.nextInt(random, 10));
  7. when(random.nextDouble()).thenReturn(Math.nextAfter(1.0, Double.NEGATIVE_INFINITY));
  8. assertEquals(99, nearbyRandom.nextInt(random, 500));
  9. }

代码示例来源:origin: kiegroup/optaplanner

  1. @Test
  2. public void createRandomIterator() {
  3. Random workingRandom = mock(Random.class);
  4. when(workingRandom.nextDouble()).thenReturn(0.3, 0.0);
  5. assertElementsOfIterator(new DoubleValueRange(0.0, 1.0).createRandomIterator(workingRandom), 0.3, 0.0);
  6. when(workingRandom.nextDouble()).thenReturn(0.3, 0.0);
  7. assertElementsOfIterator(new DoubleValueRange(100.0, 104.0).createRandomIterator(workingRandom), 101.2, 100.0);
  8. when(workingRandom.nextDouble()).thenReturn(0.3, 0.0);
  9. assertElementsOfIterator(new DoubleValueRange(-5.0, 5.0).createRandomIterator(workingRandom), -2.0, -5.0);
  10. assertAllElementsOfIterator(new DoubleValueRange(7.0, 7.0).createRandomIterator(workingRandom));
  11. when(workingRandom.nextDouble()).thenReturn(Math.nextAfter(1.0, Double.NEGATIVE_INFINITY));
  12. assertElementsOfIterator(new DoubleValueRange(0.000001, 0.000002).createRandomIterator(workingRandom),
  13. Math.nextAfter(0.000002, Double.NEGATIVE_INFINITY));
  14. when(workingRandom.nextDouble()).thenReturn(Math.nextAfter(1.0, Double.NEGATIVE_INFINITY));
  15. assertElementsOfIterator(new DoubleValueRange(1000000.0, 2000000.0).createRandomIterator(workingRandom),
  16. Math.nextAfter(2000000.0, Double.NEGATIVE_INFINITY));
  17. }

代码示例来源:origin: kiegroup/optaplanner

  1. @Test
  2. public void cornerCase() {
  3. Random random = mock(Random.class);
  4. NearbyRandom nearbyRandom = new ParabolicDistributionNearbyRandom(100);
  5. when(random.nextDouble()).thenReturn(Math.nextAfter(1.0, Double.NEGATIVE_INFINITY));
  6. assertEquals(99, nearbyRandom.nextInt(random, 500));
  7. assertEquals(9, nearbyRandom.nextInt(random, 10));
  8. when(random.nextDouble()).thenReturn(0.0);
  9. assertEquals(0, nearbyRandom.nextInt(random, 500));
  10. assertEquals(0, nearbyRandom.nextInt(random, 10));
  11. }

代码示例来源:origin: kiegroup/optaplanner

  1. when(random.nextDouble()).thenReturn(Math.nextAfter(threshold, Double.NEGATIVE_INFINITY));
  2. assertEquals(-1, nearbyRandom.nextInt(random, 1));

代码示例来源:origin: shchurov/HorizontalWheelView

  1. private boolean checkEndLock(double radians) {
  2. if (!endLock) {
  3. return false;
  4. }
  5. boolean hit = false;
  6. if (radians >= 2 * PI) {
  7. angle = Math.nextAfter(2 * PI, Double.NEGATIVE_INFINITY);
  8. hit = true;
  9. } else if (onlyPositiveValues && radians < 0) {
  10. angle = 0;
  11. hit = true;
  12. } else if (radians <= -2 * PI) {
  13. angle = Math.nextAfter(-2 * PI, Double.POSITIVE_INFINITY);
  14. hit = true;
  15. }
  16. if (hit) {
  17. touchHandler.cancelFling();
  18. }
  19. return hit;
  20. }

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

  1. @Test
  2. public void validateLatitudeTest() {
  3. LatLongUtils.validateLatitude(LatLongUtils.LATITUDE_MAX);
  4. LatLongUtils.validateLatitude(LatLongUtils.LATITUDE_MIN);
  5. verifyInvalidLatitude(Double.NaN);
  6. verifyInvalidLatitude(Math.nextAfter(LatLongUtils.LATITUDE_MAX, Double.POSITIVE_INFINITY));
  7. verifyInvalidLatitude(Math.nextAfter(LatLongUtils.LATITUDE_MIN, Double.NEGATIVE_INFINITY));
  8. }

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

  1. @Test
  2. public void validateLongitudeTest() {
  3. LatLongUtils.validateLongitude(LatLongUtils.LONGITUDE_MAX);
  4. LatLongUtils.validateLongitude(LatLongUtils.LONGITUDE_MIN);
  5. verifyInvalidLongitude(Double.NaN);
  6. verifyInvalidLongitude(Math.nextAfter(LatLongUtils.LONGITUDE_MAX, Double.POSITIVE_INFINITY));
  7. verifyInvalidLongitude(Math.nextAfter(LatLongUtils.LONGITUDE_MIN, Double.NEGATIVE_INFINITY));
  8. }

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

  1. /**
  2. * Returns the next float after {@code start} in the given {@code direction}.
  3. * @since 1.6
  4. */
  5. public static float nextAfter(float start, double direction) {
  6. return Math.nextAfter(start, direction);
  7. }

代码示例来源:origin: MobiVM/robovm

  1. /**
  2. * Returns the next float after {@code start} in the given {@code direction}.
  3. * @since 1.6
  4. */
  5. public static float nextAfter(float start, double direction) {
  6. return Math.nextAfter(start, direction);
  7. }

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

  1. import java.math.BigDecimal;
  2. public class Test
  3. {
  4. public static void main(String[] args) {
  5. double maxValue = (double)Long.MAX_VALUE;
  6. System.out.println(new BigDecimal(maxValue));
  7. double nextDown = Math.nextAfter(maxValue, 0);
  8. System.out.println(new BigDecimal(nextDown));
  9. System.out.println(maxValue-nextDown);
  10. }
  11. }

代码示例来源:origin: com.carrotsearch.randomizedtesting/randomizedtesting-runner

  1. /**
  2. * Fuzzify the input value by decreasing it by a few ulps, but never past min.
  3. */
  4. public static double fuzzDown(Random r, double v, double min) {
  5. assert v >= min;
  6. for (int steps = RandomNumbers.randomIntBetween(r, 1, 10); steps > 0 && v > min; steps--) {
  7. v = Math.nextAfter(v, Double.NEGATIVE_INFINITY);
  8. }
  9. return v;
  10. }

代码示例来源:origin: com.carrotsearch.randomizedtesting/randomizedtesting-runner

  1. /**
  2. * Fuzzify the input value by decreasing it by a few ulps, but never past min.
  3. */
  4. public static float fuzzDown(Random r, float v, float min) {
  5. assert v >= min;
  6. for (int steps = RandomNumbers.randomIntBetween(r, 1, 10); steps > 0 && v > min; steps--) {
  7. v = Math.nextAfter(v, Double.NEGATIVE_INFINITY);
  8. }
  9. return v;
  10. }

代码示例来源:origin: org.apache.druid/druid-common

  1. @Override
  2. protected ExprEval eval(double x, double y)
  3. {
  4. return ExprEval.of(Math.nextAfter(x, y));
  5. }
  6. }

代码示例来源:origin: org.ballerinalang/ballerina-math

  1. public void execute(Context ctx) {
  2. double a = ctx.getFloatArgument(0);
  3. double b = ctx.getFloatArgument(1);
  4. ctx.setReturnValues(new BFloat(Math.nextAfter(a, b)));
  5. }
  6. }

代码示例来源:origin: dremio/dremio-oss

  1. private Query toRangeQuery(RangeDouble range) {
  2. return DoublePoint.newRangeQuery(
  3. range.getField(),
  4. range.hasMin() ?
  5. range.getMinInclusive() ? range.getMin()
  6. : Math.nextUp(range.getMin())
  7. : Double.NEGATIVE_INFINITY,
  8. range.hasMax() ?
  9. range.getMaxInclusive() ? range.getMax()
  10. : Math.nextAfter(range.getMax(), -Double.MAX_VALUE)
  11. : Double.POSITIVE_INFINITY );
  12. }

代码示例来源:origin: dremio/dremio-oss

  1. private Query toRangeQuery(RangeFloat range) {
  2. return FloatPoint.newRangeQuery(
  3. range.getField(),
  4. range.hasMin() ?
  5. range.getMinInclusive() ? range.getMin()
  6. : Math.nextUp(range.getMin())
  7. : Float.NEGATIVE_INFINITY,
  8. range.hasMax() ?
  9. range.getMaxInclusive() ? range.getMax()
  10. : Math.nextAfter(range.getMax(), -Double.MAX_VALUE)
  11. : Float.POSITIVE_INFINITY );
  12. }

相关文章