當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C++ Math nexttoward()用法及代碼示例

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 nexttoward()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。