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 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短