std::nextafter,std::nextafterf,std::nextafterl,std::nexttoward,std::nexttowardf, (3) - Linux Manuals
std::nextafter,std::nextafterf,std::nextafterl,std::nexttoward,std::nexttowardf,: std::nextafter,std::nextafterf,std::nextafterl,std::nexttoward,std::nexttowardf,
Command to display std::nextafter,std::nextafterf,std::nextafterl,std::nexttoward,std::nexttowardf,
manual in Linux: $ man 3 std::nextafter,std::nextafterf,std::nextafterl,std::nexttoward,std::nexttowardf,
NAME
std::nextafter,std::nextafterf,std::nextafterl,std::nexttoward,std::nexttowardf, - std::nextafter,std::nextafterf,std::nextafterl,std::nexttoward,std::nexttowardf,
Synopsis
Defined in header <cmath>
float nextafter ( float from, float to ); (1) (since C++11)
float nextafterf( float from, float to );
double nextafter ( double from, double to ); (2) (since C++11)
long double nextafter ( long double from, long double to ); (3) (since C++11)
long double nextafterl( long double from, long double to );
Promoted nextafter ( Arithmetic1 from, Arithmetic2 to ); (4) (since C++11)
float nexttoward ( float from, long double to ); (5) (since C++11)
float nexttowardf( float from, long double to );
double nexttoward ( double from, long double to ); (6) (since C++11)
long double nexttoward ( long double from, long double to ); (7) (since C++11)
long double nexttowardl( long double from, long double to );
double nexttoward ( IntegralType from, long double to ); (8) (since C++11)
Returns the next representable value of from in the direction of to.
1-3) If from equals to to, to is returned.
5-7) 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.
4) A set of overloads or a function template for all combinations of arguments of
arithmetic type not covered by (1-3). If any argument has integral type, it is cast
to double. If any argument is long double, then the return type Promoted is also
long double, otherwise the return type is always double.
8) A set of overloads or a function template accepting the from argument of any
integral type. Equivalent to (6) (the argument is cast to double).
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.
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: std::nextafter(-0.0,
+0.0) returns +0.0 and std::nextafter(+0.0, -0.0) returns –0.0.
Example
// Run this code
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cfloat>
#include <cfenv>
int main()
{
float from1 = 0, to1 = std::nextafter(from1, 1.f);
std::cout << "The next representable float after " << std::setprecision(20) << from1
<< " is " << to1
<< std::hexfloat << " (" << to1 << ")\n" << std::defaultfloat;
float from2 = 1, to2 = std::nextafter(from2, 2.f);
std::cout << "The next representable float after " << from2 << " is " << to2
<< std::hexfloat << " (" << to2 << ")\n" << std::defaultfloat;
double from3 = std::nextafter(0.1, 0), to3 = 0.1;
std::cout <<