1 float a = 1; 2 assert(is(typeof(nextafter(a, a)) == float)); 3 assert(nextafter(a, a.infinity) > a); 4 assert(isNaN(nextafter(a, a.nan))); 5 assert(isNaN(nextafter(a.nan, a))); 6 7 double b = 2; 8 assert(is(typeof(nextafter(b, b)) == double)); 9 assert(nextafter(b, b.infinity) > b); 10 assert(isNaN(nextafter(b, b.nan))); 11 assert(isNaN(nextafter(b.nan, b))); 12 13 real c = 3; 14 assert(is(typeof(nextafter(c, c)) == real)); 15 assert(nextafter(c, c.infinity) > c); 16 assert(isNaN(nextafter(c, c.nan))); 17 assert(isNaN(nextafter(c.nan, c)));
Calculates the next representable value after x in the direction of y.
If y > x, the result will be the next largest floating-point value; if y < x, the result will be the next smallest value. If x == y, the result is y. If x or y is a NaN, the result is a NaN.
Remarks: This function is not generally very useful; it's almost always better to use the faster functions nextUp() or nextDown() instead.
The FE_INEXACT and FE_OVERFLOW exceptions will be raised if x is finite and the function result is infinite. The FE_INEXACT and FE_UNDERFLOW exceptions will be raised if the function value is subnormal, and x is not equal to y.