该函数确定数字是否为无限。它可以是正无穷大。如果数字是无限的,则返回1,否则返回0。
假设数字是“ x”。语法为:
bool isinf(float x); bool isinf(double x); bool isinf(long double x); bool isinf(integral x);
x :这是一个浮点值。
参数(x) | 返回值 |
---|---|
Finite value | Infinite value |
0 | 1 |
让我们看一个简单的例子,当x的值为1.0/0.0时。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-isinf-function.html
来源:LearnFk无涯教程网
#include <iostream> #include<math.h> using namespace std; int main() { float x=1.0/0.0; cout<<"value of x is : "<<x<<'\n'; cout<<"isinf(x) : "<<isinf(x); return 0; }
输出:
value of x is : inf isinf(x) : 1
在此示例中,isinf()函数确定x的值是无限的。因此,它返回1。
让我们看一个简单的例子,当x的值为4时。
#include <iostream> #include<math.h> using namespace std; int main() { int x=4; cout<<"value of x is : "<<x<<'\n'; cout<<"isinf(x) : "<<isinf(x); return 0; }
输出:
value of x is : 4 isinf(x) : 0
在此示例中,isinf()函数确定x的值是有限的。因此,它返回0值。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)