1nextafter(3M) Mathematical Library Functions nextafter(3M)
2
3
4
6 nextafter, nextafterf, nextafterl, nexttoward, nexttowardf, nexttowardl
7 - next representable double-precision floating-point number
8
10 c99 [ flag... ] file... -lm [ library... ]
11 #include <math.h>
12
13 double nextafter(double x, double y);
14
15
16 float nextafterf(float x, float y);
17
18
19 long double nextafterl(long double x, long double y);
20
21
22 double nexttoward(double x, long double y);
23
24
25 float nexttowardf(float x, long double y);
26
27
28 long double nexttowardl(long double x, long double y);
29
30
32 The nextafter(), nextafterf(), and nextafterl() functions compute the
33 next representable floating-point value following x in the direction of
34 y. Thus, if y is less than x, nextafter() returns the largest repre‐
35 sentable floating-point number less than x. The nextafter(),
36 nextafterf(), and nextafterl() functions return y if x equals y.
37
38
39 The nexttoward(), nexttowardf(), and nexttowardl() functions are equiv‐
40 alent to the corresponding nextafter() functions, except that the sec‐
41 ond parameter has type long double and the functions return y converted
42 to the type of the function if x equals y.
43
45 Upon successful completion, these functions return the next repre‐
46 sentable floating-point value following x in the direction of y.
47
48
49 If x == y, y (of the type x) is returned.
50
51
52 If x is finite and the correct function value would overflow, a range
53 error occurs and ±HUGE_VAL, ±HUGE_VALF, and ±HUGE_VALL (with the same
54 sign as x) is returned as appropriate for the return type of the func‐
55 tion.
56
57
58 If x or y is NaN, a NaN is returned.
59
60
61 If x != y and the correct function value is subnormal, zero, or under‐
62 flows, a range error occurs and either the correct function value (if
63 representable) or 0.0 is returned.
64
66 These functions will fail if:
67
68 Range Error The correct value overflows.
69
70 If the integer expression (math_errhandling &
71 MATH_ERREXCEPT) is non-zero, the overflow floating-point
72 exception is raised.
73
74 The nextafter() function sets errno to ERANGE if the
75 correct value would overflow.
76
77
78 Range Error The correct value underflows.
79
80 If the integer expression (math_errhandling &
81 MATH_ERREXCEPT) is non-zero, the underflow floating-
82 point exception is raised.
83
84
86 An application wanting to check for exceptions should call feclearex‐
87 cept(FE_ALL_EXCEPT) before calling these functions. On return, if
88 fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is
89 non-zero, an exception has been raised. An application should either
90 examine the return value or check the floating point exception flags to
91 detect exceptions.
92
93
94 An application can also set errno to 0 before calling nextafter(). On
95 return, if errno is non-zero, an error has occurred. The nextafterf(),
96 nextafterl(). nexttoward(), nexttowardf(), and nexttowardl() functions
97 do not set errno.
98
100 See attributes(5) for descriptions of the following attributes:
101
102
103
104
105 ┌─────────────────────────────┬─────────────────────────────┐
106 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
107 ├─────────────────────────────┼─────────────────────────────┤
108 │Interface Stability │Standard │
109 ├─────────────────────────────┼─────────────────────────────┤
110 │MT-Level │MT-Safe │
111 └─────────────────────────────┴─────────────────────────────┘
112
114 feclearexcept(3M), fetestexcept(3M), math.h(3HEAD), attributes(5),
115 standards(5)
116
117
118
119SunOS 5.11 12 Jul 2006 nextafter(3M)