IsIf()函数在C++中的应用

此函数在中定义 这个 isinf() 函数用于确定给定的数是否为无穷大,即正无穷大或负无穷大。如果给定的数字是无限的,则该函数返回1,否则该函数返回0。

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
喜欢就支持一下吧
点赞11 分享