nextafter, nextafterf, nextafterl, nexttoward, nexttowardf, nexttowardl

From cppreference.com
< c‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)(C99)(C99)
Exponential functions
(C99)
(C99)
(C99)
(C99)
Power functions
(C99)
(C99)
Trigonometric and hyperbolic functions
(C99)
(C99)
(C99)
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Nearest integer floating point operations
(C99)(C99)(C99)
(C99)
(C99)(C99)(C99)
Floating point manipulation functions
(C99)(C99)
(C99)
(C99)
nextafternexttoward
(C99)(C99)
Classification
(C99)
(C99)
(C99)
Types
(C99)(C99)
Macro constants
 
Defined in header <math.h>
float       nextafterf( float from, float to );
(1) (since C99)
double      nextafter( double from, double to );
(2) (since C99)
long double nextafterl( long double from, long double to );
(3) (since C99)
float       nexttowardf( float from, long double to );
(4) (since C99)
double      nexttoward( double from, long double to );
(5) (since C99)
long double nexttowardl( long double from, long double to );
(6) (since C99)
Defined in header <tgmath.h>
#define nextafter(from, to)
(7) (since C99)
#define nexttoward(from, to)
(8) (since C99)
1-3) First, converts both arguments to the type of the function, then returns the next representable value of from in the direction of to. If from equals to to, to is returned.
4-6) First, converts the first argument to the type of the function, then returns the next representable value of from in the direction of to. If from equals to to, to is returned, converted from long double to the return type of the function without loss of range or precision.
7) Type-generic macro: If any argument has type long double, nextafterl is called. Otherwise, if any argument has integer type or has type double, nextafter is called. Otherwise, nextafterf is called.
8) Type-generic macro: If the argument from has type long double, nexttowardl is called. Otherwise, if from has integer type or the type double, nexttoward is called. Otherwise, nexttowardf is called.

Parameters

from, to - floating point values

Return value

If no errors occur, the next representable value of from in the direction of to. is returned. If from equals to, then to is returned, converted to the type of the function.

If a range error due to overflow occurs, ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL is returned (with the same sign as from).

If a range error occurs due to underflow, the correct result is returned.

Error handling

Errors are reported as specified in math_errhandling.

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

  • if from is finite, but the expected result is an infinity, raises FE_INEXACT and FE_OVERFLOW
  • if from does not equal to and the result is subnormal or zero, raises FE_INEXACT and FE_UNDERFLOW
  • in any case, the returned value is independent of the current rounding mode
  • if either from or to is NaN, NaN is returned

Notes

POSIX specifies that the overflow and the underflow conditions are range errors (errno may be set).

IEC 60559 recommends that from is returned whenever from==to. These functions return to instead, which makes the behavior around zero consistent: nextafter(-0.0, +0.0) returns +0.0 and nextafter(+0.0, -0.0) returns –0.0.