nexttoward
Returns the next floating point number of x in the y direction.
Interface Definition
C interface:
float nexttowardf(float x, long double y);
double nexttoward(double x, long double y);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of the input data |
Input |
y |
|
Floating-point value of the input data |
Input |
Return Value
The next floating point value of x in the y direction is returned.
- If x = y, x is returned.
- If x or y is NaN, NaN is returned.
Dependencies
C: "km.h"
Examples
C interface:
// typical usage
double x1 = 1.0, x2 = 1.0;
double y1 = 1.0, y2 = 1.1;
double z1 = 1.0, z2 = 0.9;
// special handling
double e = INFINITY, f = -INFINITY, g = NAN;
// print result
printf("\t/*\n");
printf("\t * nexttoward(1.0, 1.0) = %a\n", nexttoward(x1, (long double)y1));
printf("\t * nexttoward(1.0, 1.1) = %a\n", nexttoward(y1, (long double)y2));
printf("\t * nexttoward(1.0, 0.9) = %a\n", nexttoward(z1, (long double)z2));
printf("\t * nexttoward(INFINITY, 0) = %a\n", nexttoward(e, 0.0));
printf("\t * nexttoward(-INFINITY, 1.0) = %a\n", nexttoward(f, x1));
printf("\t * nexttoward(NAN, 1.0) = %a\n", nexttoward(g, x1));
printf("\t * nexttoward(NAN, INFINITY) = %a\n", nexttoward(g, e));
printf("\t */\n");
return 0;
/*
* nexttoward(1.0, 1.0) = 0x1p+0
* nexttoward(1.0, 1.1) = 0x1.0000000000001p+0
* nexttoward(1.0, 0.9) = 0x1.fffffffffffffp-1
* nexttoward(INFINITY, 0) = 0x1.fffffffffffffp+1023
* nexttoward(-INFINITY, 1.0) = -0x1.fffffffffffffp+1023
* nexttoward(NAN, 1.0) = nan
* nexttoward(NAN, INFINITY) = nan
*/
Parent topic: Function Syntax