當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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++。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。