ISFITEIE()函数是C++中的Bu建Tin函数,用于确定给定值是否为有限值。有限值是一个既不是无限也不是NAN的值。如果数字是有限的,那么函数返回1,否则返回零。 语法:
null
bool isfinite(float x); or,bool isfinite(double x);or, bool isfinite(long double x);
参数: 此函数只接受一个参数 .它表示浮点数。 返回: 如果数字是无穷大或NAN,则返回0;如果数字是有限的,则返回1。 下面的程序演示了C++中的isfinite()函数: 项目1:
CPP
// C++ program to illustrate the // isfinite() function. #include <bits/stdc++.h> using namespace std; int main() { float x = 19.0; cout<< "The value of x is = " << x << endl; // Here function check whether 19 is finite or not // if yes function returns 1, else 0 cout<< "isfinite(x) = " <<isfinite(x); return 0; } |
输出:
The value of x is = 19isfinite(x) = 1
项目2:
CPP
// C++ program to illustrate the // isfinite() function #include <bits/stdc++.h> using namespace std; int main() { float x=9.6/0.0; cout<< "The value of x is = " << x << endl; cout<< "isfinite(x) = " <<isfinite(x); return 0; } |
输出:
The value of x is = infisfinite(x) = 0
方案3:
CPP
// C++ program to illustrate the // isfinite() function #include <bits/stdc++.h> using namespace std; int main() { // Value is NAN double x=0.0/0.0; cout<< "Value of x is = " << x << endl; cout<< "isfinite(x) = " <<isfinite(x); return 0; } |
输出:
Value of x is = -nanisfinite(x) = 0
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END