C++ nexttoward() 函數
nexttoward() 函數是cmath頭文件的庫函數,用於在給定的第二個數字的方向上獲取給定的第一個數字之後的下一個可表示的值,它接受兩個數字(x, y
) 並在之後返回下一個可表示的值x
在...方向y
。
注意:nexttoward() 函數類似於 nextafter() 函數,但它返回下一個可表示的值,可能更精確y
。
nexttoward() 函數的語法:
nexttoward(x, y);
參數: x, y
– 是用於查找下一個可表示值的數字x
在...方向y
。
返回值: float/double/long double
– 基於輸入類型,它返回下一個可表示的值x
。
例:
Input: float x = 0.0; long double y = 1.0L; Function call: nexttoward(x,y); Output: 1.4013e-45
C++代碼演示nexttoward()函數的例子
// C++ code to demonstrate the example of
// nexttoward() function
#include <iostream>
#include <cmath>
using namespace std;
// main() section
int main()
{
float x;
long double y;
x = 0.0;
y = 1.0L;
cout<<"nexttoward("<<x<<","<<y<<"):"<<nexttoward(x,y);
cout<<endl;
x = 0.0;
y = 1.1L;
cout<<"nexttoward("<<x<<","<<y<<"):"<<nexttoward(x,y);
cout<<endl;
x = 0.0;
y = -1.0L;
cout<<"nexttoward("<<x<<","<<y<<"):"<<nexttoward(x,y);
cout<<endl;
x = 0.1;
y = 0.1L;
cout<<"nexttoward("<<x<<","<<y<<"):"<<nexttoward(x,y);
cout<<endl;
return 0;
}
輸出
nexttoward(0,1):1.4013e-45 nexttoward(0,1.1):1.4013e-45 nexttoward(0,-1):-1.4013e-45 nexttoward(0.1,0.1):0.1
參考:C++ nexttoward() 函數
相關用法
- C++ nextafter()用法及代碼示例
- C++ negate用法及代碼示例
- C++ nearbyint()用法及代碼示例
- C++ norm()用法及代碼示例
- C++ none_of()用法及代碼示例
- C++ nanl()用法及代碼示例
- C++ nanf()用法及代碼示例
- C++ nan()用法及代碼示例
- C++ unordered_map cbegin用法及代碼示例
- C++ map lower_bound()用法及代碼示例
- C++ list assign()用法及代碼示例
- C++ std::max()用法及代碼示例
- C++ std::string::push_back()用法及代碼示例
- C++ multimap key_comp()用法及代碼示例
- C++ Deque erase()用法及代碼示例
- C++ std::less_equal用法及代碼示例
- C++ set rbegin()用法及代碼示例
- C++ llround()用法及代碼示例
- C++ getline(string)用法及代碼示例
- C++ boost::algorithm::all_of()用法及代碼示例
注:本文由純淨天空篩選整理自 nexttoward() function with example in C++。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。