isnormal() 在 C++ 编程中的作用
在本文中,我们将讨论 C++ STL 中 isnormal() 函数的工作原理、语法和示例。
Isnormal() 是<cmath>头文件中的一个函数。此函数用于检查给定的数字是否为正常数字。
什么是正常数字?
如果实数的基数不是零、无限大、NAN 或非规格,则称该实数为正常数字。
语法
bool isnormal(float num);
参数
该函数仅接受一个 float 类型的参数 num。
返回值
如果数字是正常数字则返回 1,否则返回 0。
示例
Input: isnormal(5.0); Output: 1 Input: isnormal(0.0); Output: 0
示例
#include <bits/stdc++.h> using namespace std; int main() { //For Float cout<<"\n For Float : "; float var_1 = 5.89F; //when value is other than zero cout<<"check for isnormal(5.89F) : "<<isnormal(var_1); //when value is zero var_1 = 0.0F; cout<<"\ncheck for isnormal(0.0F) : "<<isnormal(var_1); //when its a infinite value by dividing it with 0.0 var_1 = 2.2F; cout<<"\ncheck for isnormal(2.2F/0.0F) : "<<isnormal(var_1/0.0F); //For double cout<<"\n\n For Double : "; double var_2 = 5.89; //when value is other than zero cout<<"check for isnormal(5.89) : "<<isnormal(var_2); //when value is zero var_2 = 0.0; cout<<"\ncheck for isnormal(0.0) : "<<isnormal(var_2); //when its a infinite value by dividing it with 0.0 var_2 = 2.2; cout<<"\ncheck for isnormal(2.2/0.0) : "<<isnormal(var_2/0.0); //For Long double cout<<"\n\n For Long Double : "; long double var_3 = 5.89; //when value is other than zero cout<<"check for isnormal(5.89) : "<<isnormal(var_3); //when value is zero var_3 = 0.0; cout<<"\ncheck for isnormal(0.0) : "<<isnormal(var_3); //when its a infinite value by dividing it with 0.0 var_3 = 2.2; cout<<"\ncheck for isnormal(2.2/0.0) : "<<isnormal(var_3/0.0); return 0; }
输出
如果我们运行上述代码,它将生成以下输出−
For Float : check for isnormal(5.89F) : 1 check for isnormal(0.0F) : 0 check for isnormal(2.2F/0.0F) : 0 For Double : check for isnormal(5.89) : 1 check for isnormal(0.0) : 0 check for isnormal(2.2/0.0) : 0 For Long Double : check for isnormal(5.89) : 1 check for isnormal(0.0) : 0 check for isnormal(2.2/0.0) : 0
广告