English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Funzioni di Libreria <cmath> in C++
Utilizzo e esempio della funzione nextafter() in C++
La funzione nextafter(x, y) in C++ utilizza due parametri e restituisce il valore rappresentabile successivo a x nella direzione di y.<cmath>Definito nel file di intestazione.
double nextafter(double x, double y); float nextafter(float x, float y); long double nextafter(long double x, long double y); Promoted nextafter(Type1 x, Type2 y); // sovraccarichi aggiuntivi
A partire dalla versione C++ 11, se il tipo di parametro passato a nextafter() è long double, il tipo restituito Promoted è long double. Altrimenti, il tipo restituito Promoted è double.
x: valore di base.
y: valore approssimativo della return value.
La funzione nextafter() restituisce il valore rappresentabile successivo a x nella direzione di y.
#include <iostream> #include <cmath> using namespace std; int main() { double x = 0.0, y = 1.0; double resultInDouble = nextafter(x, y); cout << "nextafter(x, y) = " << resultInDouble << endl; return 0; }
L'output del programma è:
nextafter(x, y) = 4.94066e-324
#include <iostream> #include <cmath> using namespace std; int main() { float y = 1.0; double x = INFINITY; double result = nextafter(x, y); cout << "nextafter(x, y) = " << result << endl; return 0; }
L'output del programma è:
nextafter(x, y) = 1.79769e+308