此函数在中定义
null
语法:
bool isinf( float arg );
或
bool isinf( double arg );
或
bool isinf( long double arg );
参数: 此函数接受一个强制参数 十、 它表示给定的浮点值。
返回: 此函数返回 1. 如果给定的数字为无穷大,则返回 零 .
下面的程序演示了C++中的isinf()函数:
例1:- 显示返回1的无限大小写
// c++ program to demonstrate // example of isnormal() function. #include <bits/stdc++.h> using namespace std; int main() { float f = 6.0F; // check for +ve infinite value cout << "isinf(6.0/0.0) is = " << isinf(f/0.0) << endl; // check for -ve infinite value f = -1.2F; cout << "isinf(-1.2/0.0) is = " << isinf(f/0.0) << endl; return 0; } |
输出:
isinf(6.0/0.0) is = 1 isinf(-1.2/0.0) is = 1
说明: 在示例1中,浮点数表示无穷大,这就是函数返回1的原因。
例2:- 显示返回0的非无限大小写
// c++ program to demonstrate // example of isinf() function. #include <bits/stdc++.h> using namespace std; int main() { cout << "isinf(0.0) is = " << isinf(0.0) << endl; cout << "isinf(sqrt(-1.0)) is = " << isinf( sqrt (-1.0)) << endl; return 0; } |
输出:
isinf(0.0) is = 0 isinf(sqrt(-1.0)) is = 0
例外情况: 在示例2中,给定的浮点数并不代表无穷大,这就是函数返回零的原因。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END