C ++中的nexttoward()函数以及示例
C++nexttoward()函数
nexttoward()函数是cmath标头的库函数,用于在给定第二个数字的方向上获取给定第一个数字之后的下一个可表示值,它接受两个数字(x,y)并在之后返回下一个可表示值x沿y方向。
注意:nexttoward()函数与nextafter()函数类似,但它返回下一个可表示的值,其中可能包含更精确的y。
nexttoward()函数语法:
nexttoward(x, y);
参数:x,y–是用于在y方向上查找x的下一个可表示值的数字。
返回值:float/double/longdouble-根据输入类型,它返回x的下一个可表示值。
示例
Input:
float x = 0.0;
long double y = 1.0L;
Function call:
nexttoward(x,y);
Output:
1.4013e-45C++代码演示nexttoward()函数示例
//示例
// nexttoward()功能
#include <iostream>
#include <cmath>
using namespace std;
// main()部分
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
热门推荐
10 毛笔哥哥结婚祝福语简短
11 向国庆送祝福语简短
12 建队节祝福语简短
13 朋友喜得外孙简短祝福语
14 小店营业的祝福语简短
15 餐饮生日祝福语简短独特
16 鲜花英语祝福语卡片简短
17 男朋友暴富祝福语简短
18 婶婶拜年祝福语大全简短