Die Funktion nexttoward () in C ++ verwendet zwei Argumente und gibt den nächsten darstellbaren Wert nach x in Richtung y zurück.
Die Funktion ist in der Header-Datei definiert.
Es ist identisch mit nextafter (), außer dass das zweite Argument von nexttoward () immer vom Typ ist long double
.
nexttoward () Prototyp (Stand C ++ 11 Standard)
doppeltes nächstes (doppeltes x, langes doppeltes y); float nexttoward (float x, long float y); langes doppeltes nächstes (langes doppeltes x, langes doppeltes y); doppeltes nächstes (T x, langes doppeltes y); // Für integralen Typ
Die nexttoward () Funktion nimmt ein zwei Argumente und gibt einen Wert vom Typ double
, float
oder long double
Typ.
nexttoward () Parameter
- x : Der Basiswert.
- y : Der Wert, auf den der Rückgabewert angenähert wird.
nexttoward () Rückgabewert
Die Funktion nexttoward () gibt den nächsten darstellbaren Wert nach x in Richtung y zurück.
Beispiel 1: Wie funktioniert die Funktion nexttoward () in C ++?
#include #include using namespace std; int main() ( long double y = -1.0; double x = 0.0; double result = nexttoward(x, y); cout << "nexttoward(x, y) = " << result << endl; return 0; )
Wenn Sie das Programm ausführen, lautet die Ausgabe wie folgt:
nexttoward (x, y) = -4,94066e-324
Beispiel 2: nexttoward () -Funktion für Integraltypen
#include #include #include using namespace std; int main() ( long double y = INFINITY; int x = INT_MAX; double result = nexttoward(x,y); cout << "nexttoward(x, y) = " << result << endl; return 0; )
Wenn Sie das Programm ausführen, lautet die Ausgabe wie folgt:
nexttoward (x, y) = 2.14748e + 09