La funzione nexttoward () in C ++ accetta due argomenti e restituisce il valore rappresentabile successivo dopo x nella direzione di y.
La funzione è definita nel file di intestazione.
È identico a nextafter () tranne per il fatto che il secondo argomento di nexttoward () è sempre di tipo long double
.
prototipo nexttoward () (come dallo standard C ++ 11)
double nexttoward (doppia x, lunga doppia y); float nexttoward (float x, long float y); lungo doppio successivo verso (lungo doppio x, lungo doppio y); doppio nexttoward (T x, long double y); // Per il tipo integrale
La funzione nexttoward () richiede due argomenti e restituisce un valore di tipo double
, float
o long double
tipo.
nexttoward () Parametri
- x : il valore di base.
- y : il valore verso il quale viene approssimato il valore restituito.
nexttoward () Restituisce il valore
La funzione nexttoward () restituisce il valore rappresentabile successivo dopo x nella direzione di y.
Esempio 1: come funziona la funzione 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; )
Quando esegui il programma, l'output sarà:
avanti (x, y) = -4,94066e-324
Esempio 2: funzione nexttoward () per i tipi integrali
#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; )
Quando esegui il programma, l'output sarà:
avanti (x, y) = 2,14748e + 09