📜  C++中的isnormal()

📅  最后修改于: 2021-05-30 09:40:05             🧑  作者: Mango

此函数在定义。通过使用isnormal()函数,我们可以确定给定的数字是否正常(既不是零,无穷也不是NAN)。如果数字正常,则此函数返回1,否则返回零。

句法:

bool  isnormal(float x);

或者

bool  isnormal(double x); 

或者

bool  isnormal(long double x); 

参数:该函数采用一个强制参数x ,该参数代表浮点值。

返回:如果给定值是正常值,则该函数返回1,否则该函数返回0

下面的程序说明了C++中的isnormal()函数:

示例1:-以浮点值显示

// c++ program to demonstrate
// example of isnormal() function.
  
#include 
  
using namespace std;
  
int main()
{
  
    float f = 7.0F;
  
    // check for non-zero value
    cout << "isnormal(7.0) is = " << isnormal(f) << endl;
  
    // check for zero
    f = 0.0F;
    cout << "isnormal(0.0) is = " << isnormal(f) << endl;
  
    // check for infinite value
    f = 9.2F;
    cout << "isnormal(9.2/0.0) is = " << isnormal(f / 0.0) << endl;
  
    return 0;
}
输出:
isnormal(7.0) is = 1
isnormal(0.0) is = 0
isnormal(9.2/0.0) is = 0

示例2:-以双精度值显示

// c++ program to demonstrate
// example of isnormal() function.
  
#include 
  
using namespace std;
  
int main()
{
  
    double f = 7.0;
  
    // check for non-zero value
    cout << "isnormal(7.0) is = " << isnormal(f) << endl;
  
    // check for zero
    f = 0.0;
    cout << "isnormal(0.0) is = " << isnormal(f) << endl;
  
    // check for infinite value
    f = 9.2;
    cout << "isnormal(9.2/0.0) is = " << isnormal(f / 0.0) << endl;
  
    return 0;
}
输出:
isnormal(7.0) is = 1
isnormal(0.0) is = 0
isnormal(9.2/0.0) is = 0

示例3:-以长整型值显示

// c++ program to demonstrate
// example of isnormal() function.
  
#include 
  
using namespace std;
  
int main()
{
  
    long double f = 7.0;
  
    // check for non-zero value
    cout << "isnormal(7.0) is = " << isnormal(f) << endl;
  
    // check for zero
    f = 0.0;
    cout << "isnormal(0.0) is = " << isnormal(f) << endl;
  
    // check for infinite value
    f = 9.2;
    cout << "isnormal(9.2/0.0) is = " << isnormal(f / 0.0) << endl;
  
    return 0;
}
输出:
isnormal(7.0) is = 1
isnormal(0.0) is = 0
isnormal(9.2/0.0) is = 0
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”