English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C++ Biblioteca de Funções <cmath>
C ++usa dois parâmetros e retorna o próximo valor representável após x na direção de y.
A função<cmath>definido no cabeçalho.
double nextafter(double x, double y); float nextafter(float x, float y); long double nextafter(long double x, long double y); nextafter() Promoted(Tipo1 x, Tipo2 y); // Overloads adicionais
A partir do C ++ 11A partir do C, se os parâmetros passados para a função nextafter() forem long double, o tipo Promoted é long double. Caso contrário, o tipo Promoted é double.
x:valor básico.
y:valor aproximado do retorno.
a função nextafter() retorna o próximo valor representável após x na direção de 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; }
A saída do programa é:
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; }
A saída do programa é:
nextafter(x, y) = 1.79769e+308