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 生日广州男生祝福语简短