C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Math nexttoward()

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"的值。 如果没有错误发生,则返回" 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、

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4