nexttoword() 函數表示特定方向上的下一個可表示值。 nextafter() 和 nexttoward() 這兩個函數的工作方式相似,返回的值相同。唯一的區別在於它們的語法。
用法
float nexttoward(float from, long double to);
double nexttoward(double from, long double to);
long double nexttoward(long double from, long double to);
double nexttoward(integral from, long double to);
參數
( from , to ):這些是浮點值。
返回值
- 如果 'from' 等於 'to',則返回 'from' 的值。
- 如果沒有發生錯誤,則返回 'from' 的下一個可表示值。
示例
讓我們看一個簡單的例子。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
long double from=0.0;
double to= -1.0;
cout<<"Values of from and to are:"<<from<<", "<<to<<'\n';
cout<<nexttoward(from,to);
return 0;
}
輸出:
Values of from and to are:0, -1 -3.6452e-4951
在上麵的例子中,'from' 和 'to' 是不同的類型。 nexttoward() 函數返回值,即 -3.6452e-4951。
相關用法
- C++ Math nextafter()用法及代碼示例
- C++ Math nearbyint()用法及代碼示例
- C++ Math scalbn()用法及代碼示例
- C++ Math acosh()用法及代碼示例
- C++ Math asinh()用法及代碼示例
- C++ Math isgreater()用法及代碼示例
- C++ Math fabs()用法及代碼示例
- C++ Math islessgreater()用法及代碼示例
- C++ Math log2()用法及代碼示例
- C++ Math tan()用法及代碼示例
- C++ Math log()用法及代碼示例
- C++ Math fdim()用法及代碼示例
- C++ Math isfinite()用法及代碼示例
- C++ Math erfc()用法及代碼示例
- C++ Math sinh()用法及代碼示例
- C++ Math scalbln()用法及代碼示例
- C++ Math cosh()用法及代碼示例
- C++ Math fma()用法及代碼示例
- C++ Math pow()用法及代碼示例
- C++ Math atan()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Math nexttoward()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。