When having a Double d, I'd like to know which Double' is the smalles possible value bigger than d.
When d==0 I know the answer, that will be Double.MIN_VALUE :
> 0d + Double.MIN_VALUE
4.9E-324
But what about all ohter numbers like for instance 1d ?
> 1d + Double.MIN_VALUE
1.0
It has to do wit significant numbers I guess, but in short : I'm looking for a method that gives me the next double
nextDouble(0)==4.9E-324
Take a look at these functions.
public static double nextAfter(double start, double direction)
Returns the floating-point number adjacent to the first argument in the direction of the second argument. If both arguments compare as equal the second argument is returned.
public static double nextUp(double d)
Returns the floating-point value adjacent to d in the direction of positive infinity. This method is semantically equivalent to
nextAfter(d, Double.POSITIVE_INFINITY);
however, a nextUp implementation may run faster than its equivalent nextAfter call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With