当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C++ isnormal()用法及代码示例


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

用法:

bool  isnormal(float x);

或者


bool  isnormal(double x); 

或者

bool  isnormal(long double x); 

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

返回:如果给定值正常,则函数返回1,否则函数返回零。

以下示例程序旨在说明C++中的isnormal()函数:

示例1:以浮点值显示

// c++ program to demonstrate 
// example of isnormal() function. 
  
#include <bits/stdc++.h> 
  
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 <bits/stdc++.h> 
  
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 <bits/stdc++.h> 
  
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


相关用法


注:本文由纯净天空筛选整理自bansal_rtk_大神的英文原创作品 isnormal() in C++。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。