nexttoward(x,y)函数详解

首页 / C++入门教程 / nexttoward(x,y)函数详解

nexttoword()函数表示特定方向上的下一个可表示值。 nextafter()和nexttoward()这两个函数的工作类似,并返回相同的值。唯一的区别在于语法。

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

nexttoward - 参数

(from,to):这些是浮点值。

nexttoward - 返回值

  • 如果" from"等于" to",则返回" from"的值。
  • 如果没有错误发生,则返回" from"的下一个可表示值。

nexttoward - 示例

让我们看一个简单的例子。

#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。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Service Mesh实践指南 -〔周晶〕

Go语言从入门到实战 -〔蔡超〕

从0打造音视频直播系统 -〔李超〕

摄影入门课 -〔小麥〕

RPC实战与核心原理 -〔何小锋〕

微信小程序全栈开发实战 -〔李艺〕

软件设计之美 -〔郑晔〕

玩转Vue 3全家桶 -〔大圣〕

B端产品经理入门课 -〔董小圣〕

好记忆不如烂笔头。留下您的足迹吧 :)