nextafter
You can use the nextafter functions to find out the next value that can be represented after a given value in a particular floating-point type.
float nextafterf (float x, float y); double nextafterd (double x, double y);
x
- Any floating-point number.
y
- Any floating-point number.
DESCRIPTION
The nextafter functions (one for each data type) generate the next representable neighbor ofx
in the direction ofy
in the proper format.The floating-point values representable in single and double formats constitute a finite set of real numbers. The nextafter functions illustrate this fact by returning the next representable value.
If , returns x if x and y are not signed zeros.
EXCEPTIONS
When x and y are finite and nonzero, either the result of is exact or it raises one of the following exceptions:
- inexact (if an overflow or underflow exception occurs)
- overflow (if x is finite and the result is infinite)
- underflow (if the result is inexact, must be represented as a denormalized number
or 0, and xy)
SPECIAL CASES
Table 10-39 shows the results when one of the arguments to a nextafter function is a zero, a NaN, or an Infinity. In this table, x and y are finite, nonzero floating-point numbers.
Table 10-39 Special cases for the nextafter functions Operation Result Exceptions raised Next representable number in direction of y Underflow Next representable number in direction of 0 None Next representable number in direction of y Underflow +0 None Next representable number in direction of 0 None None NaN[63] None[64] NaN None Largest respresentable number None[64] Next representable number greater than x None Smallest representable number None Next representable number smaller than x None EXAMPLES
z = nextafterf(1.0, +);/* z = 1.000000000000000000000012
1.000000119209289551 */ z = nextafterd(1.0, +
);/* z = 1.00000000...0000000000000000012
1.000000000000000222 */
[63] If both arguments are NaNs, the value of the first NaN is returned.
[64] If the NaN is a signaling NaN, the invalid exception is raised.