#include <cmath>
double nextafter (double x, double y) double nexttoward (double x, long double y)
Liefert die nächste darstellbare Gleitkommazahl nach x in Richtung y.
Beide Funktionen unterscheiden sich nur im Typ des zweiten Parameters.
Überladungen für float und long double existieren.
x | Gleitkommazahl |
y | (lange) Gleitkommazahl |
Rückgabewert: nächster darstellbarer Wert von x ausgehend in Richtung y. Falls x==y, wird y geliefert und ggf. in den Zieltyp konvertiert.
#include <cmath> #include <iostream> int main() { double x = 12.345; std::cout << std::nextafter(x, x+1) << '\n'; }