本文整理了Java中java.lang.Math.nextAfter()
方法的一些代码示例,展示了Math.nextAfter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.nextAfter()
方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:nextAfter
[英]Returns the next double after start in the given direction.
[中]返回给定方向上开始后的下一个双精度。
代码示例来源:origin: robovm/robovm
/**
* 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);
}
代码示例来源:origin: apache/incubator-druid
@Override
protected ExprEval eval(double x, double y)
{
return ExprEval.of(Math.nextAfter(x, y));
}
}
代码示例来源:origin: kiegroup/optaplanner
@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;
}
代码示例来源:origin: HdrHistogram/HdrHistogram
Math.min(Math.max(Math.nextAfter(percentile, Double.NEGATIVE_INFINITY), 0.0D), 100.0D);
代码示例来源:origin: kiegroup/optaplanner
@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));
}
代码示例来源:origin: kiegroup/optaplanner
@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));
}
代码示例来源:origin: kiegroup/optaplanner
@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));
}
代码示例来源:origin: kiegroup/optaplanner
when(random.nextDouble()).thenReturn(Math.nextAfter(threshold, Double.NEGATIVE_INFINITY));
assertEquals(-1, nearbyRandom.nextInt(random, 1));
代码示例来源:origin: shchurov/HorizontalWheelView
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;
}
代码示例来源:origin: mapsforge/mapsforge
@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));
}
代码示例来源:origin: mapsforge/mapsforge
@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));
}
代码示例来源:origin: com.mobidevelop.robovm/robovm-rt
/**
* 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);
}
代码示例来源:origin: MobiVM/robovm
/**
* 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);
}
代码示例来源:origin: stackoverflow.com
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);
}
}
代码示例来源:origin: com.carrotsearch.randomizedtesting/randomizedtesting-runner
/**
* 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;
}
代码示例来源:origin: com.carrotsearch.randomizedtesting/randomizedtesting-runner
/**
* 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;
}
代码示例来源:origin: org.apache.druid/druid-common
@Override
protected ExprEval eval(double x, double y)
{
return ExprEval.of(Math.nextAfter(x, y));
}
}
代码示例来源:origin: org.ballerinalang/ballerina-math
public void execute(Context ctx) {
double a = ctx.getFloatArgument(0);
double b = ctx.getFloatArgument(1);
ctx.setReturnValues(new BFloat(Math.nextAfter(a, b)));
}
}
代码示例来源:origin: dremio/dremio-oss
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 );
}
代码示例来源:origin: dremio/dremio-oss
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 );
}
内容来源于网络,如有侵权,请联系作者删除!