/** * Returns the next float after {@code start} in the given {@code direction}. * @since 1.6 */ public static float nextAfter(float start, double direction) { return Math.nextAfter(start, direction); }
@Override protected ExprEval eval(double x, double y) { return ExprEval.of(Math.nextAfter(x, y)); } }
@Override public Double next() { if (to == from) { throw new NoSuchElementException(); } double diff = to - from; double next = from + diff * workingRandom.nextDouble(); if (next >= to) { // Rounding error occurred next = Math.nextAfter(next, Double.NEGATIVE_INFINITY); } return next; }
Math.min(Math.max(Math.nextAfter(percentile, Double.NEGATIVE_INFINITY), 0.0D), 100.0D);
@Test public void cornerCase() { Random random = mock(Random.class); NearbyRandom nearbyRandom = new LinearDistributionNearbyRandom(100); when(random.nextDouble()).thenReturn(Math.nextAfter(1.0, Double.NEGATIVE_INFINITY)); assertEquals(9, nearbyRandom.nextInt(random, 10)); when(random.nextDouble()).thenReturn(Math.nextAfter(1.0, Double.NEGATIVE_INFINITY)); assertEquals(99, nearbyRandom.nextInt(random, 500)); }
@Test public void createRandomIterator() { Random workingRandom = mock(Random.class); when(workingRandom.nextDouble()).thenReturn(0.3, 0.0); assertElementsOfIterator(new DoubleValueRange(0.0, 1.0).createRandomIterator(workingRandom), 0.3, 0.0); when(workingRandom.nextDouble()).thenReturn(0.3, 0.0); assertElementsOfIterator(new DoubleValueRange(100.0, 104.0).createRandomIterator(workingRandom), 101.2, 100.0); when(workingRandom.nextDouble()).thenReturn(0.3, 0.0); assertElementsOfIterator(new DoubleValueRange(-5.0, 5.0).createRandomIterator(workingRandom), -2.0, -5.0); assertAllElementsOfIterator(new DoubleValueRange(7.0, 7.0).createRandomIterator(workingRandom)); when(workingRandom.nextDouble()).thenReturn(Math.nextAfter(1.0, Double.NEGATIVE_INFINITY)); assertElementsOfIterator(new DoubleValueRange(0.000001, 0.000002).createRandomIterator(workingRandom), Math.nextAfter(0.000002, Double.NEGATIVE_INFINITY)); when(workingRandom.nextDouble()).thenReturn(Math.nextAfter(1.0, Double.NEGATIVE_INFINITY)); assertElementsOfIterator(new DoubleValueRange(1000000.0, 2000000.0).createRandomIterator(workingRandom), Math.nextAfter(2000000.0, Double.NEGATIVE_INFINITY)); }
@Test public void cornerCase() { Random random = mock(Random.class); NearbyRandom nearbyRandom = new ParabolicDistributionNearbyRandom(100); when(random.nextDouble()).thenReturn(Math.nextAfter(1.0, Double.NEGATIVE_INFINITY)); assertEquals(99, nearbyRandom.nextInt(random, 500)); assertEquals(9, nearbyRandom.nextInt(random, 10)); when(random.nextDouble()).thenReturn(0.0); assertEquals(0, nearbyRandom.nextInt(random, 500)); assertEquals(0, nearbyRandom.nextInt(random, 10)); }
when(random.nextDouble()).thenReturn(Math.nextAfter(threshold, Double.NEGATIVE_INFINITY)); assertEquals(-1, nearbyRandom.nextInt(random, 1));
private boolean checkEndLock(double radians) { if (!endLock) { return false; } boolean hit = false; if (radians >= 2 * PI) { angle = Math.nextAfter(2 * PI, Double.NEGATIVE_INFINITY); hit = true; } else if (onlyPositiveValues && radians < 0) { angle = 0; hit = true; } else if (radians <= -2 * PI) { angle = Math.nextAfter(-2 * PI, Double.POSITIVE_INFINITY); hit = true; } if (hit) { touchHandler.cancelFling(); } return hit; }
@Test public void validateLatitudeTest() { LatLongUtils.validateLatitude(LatLongUtils.LATITUDE_MAX); LatLongUtils.validateLatitude(LatLongUtils.LATITUDE_MIN); verifyInvalidLatitude(Double.NaN); verifyInvalidLatitude(Math.nextAfter(LatLongUtils.LATITUDE_MAX, Double.POSITIVE_INFINITY)); verifyInvalidLatitude(Math.nextAfter(LatLongUtils.LATITUDE_MIN, Double.NEGATIVE_INFINITY)); }
@Test public void validateLongitudeTest() { LatLongUtils.validateLongitude(LatLongUtils.LONGITUDE_MAX); LatLongUtils.validateLongitude(LatLongUtils.LONGITUDE_MIN); verifyInvalidLongitude(Double.NaN); verifyInvalidLongitude(Math.nextAfter(LatLongUtils.LONGITUDE_MAX, Double.POSITIVE_INFINITY)); verifyInvalidLongitude(Math.nextAfter(LatLongUtils.LONGITUDE_MIN, Double.NEGATIVE_INFINITY)); }
/** * Returns the next float after {@code start} in the given {@code direction}. * @since 1.6 */ public static float nextAfter(float start, double direction) { return Math.nextAfter(start, direction); }
/** * Returns the next float after {@code start} in the given {@code direction}. * @since 1.6 */ public static float nextAfter(float start, double direction) { return Math.nextAfter(start, direction); }
import java.math.BigDecimal; public class Test { public static void main(String[] args) { double maxValue = (double)Long.MAX_VALUE; System.out.println(new BigDecimal(maxValue)); double nextDown = Math.nextAfter(maxValue, 0); System.out.println(new BigDecimal(nextDown)); System.out.println(maxValue-nextDown); } }
/** * Fuzzify the input value by decreasing it by a few ulps, but never past min. */ public static double fuzzDown(Random r, double v, double min) { assert v >= min; for (int steps = RandomNumbers.randomIntBetween(r, 1, 10); steps > 0 && v > min; steps--) { v = Math.nextAfter(v, Double.NEGATIVE_INFINITY); } return v; }
/** * Fuzzify the input value by decreasing it by a few ulps, but never past min. */ public static float fuzzDown(Random r, float v, float min) { assert v >= min; for (int steps = RandomNumbers.randomIntBetween(r, 1, 10); steps > 0 && v > min; steps--) { v = Math.nextAfter(v, Double.NEGATIVE_INFINITY); } return v; }
@Override protected ExprEval eval(double x, double y) { return ExprEval.of(Math.nextAfter(x, y)); } }
public void execute(Context ctx) { double a = ctx.getFloatArgument(0); double b = ctx.getFloatArgument(1); ctx.setReturnValues(new BFloat(Math.nextAfter(a, b))); } }
private Query toRangeQuery(RangeDouble range) { return DoublePoint.newRangeQuery( range.getField(), range.hasMin() ? range.getMinInclusive() ? range.getMin() : Math.nextUp(range.getMin()) : Double.NEGATIVE_INFINITY, range.hasMax() ? range.getMaxInclusive() ? range.getMax() : Math.nextAfter(range.getMax(), -Double.MAX_VALUE) : Double.POSITIVE_INFINITY ); }
private Query toRangeQuery(RangeFloat range) { return FloatPoint.newRangeQuery( range.getField(), range.hasMin() ? range.getMinInclusive() ? range.getMin() : Math.nextUp(range.getMin()) : Float.NEGATIVE_INFINITY, range.hasMax() ? range.getMaxInclusive() ? range.getMax() : Math.nextAfter(range.getMax(), -Double.MAX_VALUE) : Float.POSITIVE_INFINITY ); }