亚洲区国产区激情区无码区,国产成人mv视频在线观看,国产A毛片AAAAAA,亚洲精品国产首次亮相在线

C++ nexttoward() 函數(shù)使用方法及示例

C++ 庫函數(shù) <cmath>

C ++中的nexttoward(x,y)函數(shù)采用兩個參數(shù),返回x之后y方向上的下一個可表示值。

該函數(shù)在<cmath>頭文件中定義。

它與nextafter()相同,除了nexttoward()的第二個參數(shù)始終為type long double。

nexttoward()原型[從C ++ 11標準開始]

double nexttoward(double x, long double y);
float nexttoward(float x, long float y);
long double nexttoward(long double x, long double y);
double nexttoward(T x, long double y); // For integral type

nexttoward()函數(shù)獲得兩個參數(shù),并返回類型的值double,float或long double類型。

nexttoward()參數(shù)

  • x:基本值。

  • y:近似返回值的值。

nexttoward()返回值

nexttoward()函數(shù)在y方向上返回x之后的下一個可表示值。

示例1:nexttoward()函數(shù)在C ++中如何工作?

#include <iostream>
#include <cmath>

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;
}

運行該程序時,輸出為:

nexttoward(x, y) = -4.94066e-324

示例2:整數(shù)類型的nexttoward()函數(shù)

#include <iostream>
#include <cmath>
#include <climits>

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;
}

運行該程序時,輸出為:

nexttoward(x, y) = 2.14748e+09

C++ 庫函數(shù) <cmath>