C++ 中的 isnormal() 函数
c++server side programmingprogramming
本节我们将学习 C++ 中的 isnormal() 函数。该函数位于 cmath 库中。它用于检查一个数字是否为正常数。非正常数包括零、无穷大或 NAN。
该函数接受浮点型、双精度型或长双精度型值作为参数。如果数字为正常数,则返回 1;否则,返回 0。
示例
#include<iostream> #include<cmath> using namespace std; int main() { cout << "isnormal(" << 5.23 << "): " << isnormal(5.23) << endl; cout << "isnormal(" << 0.00 << "): " << isnormal(0.00) << endl; cout << "isnormal(" << 2.0/0.0 << "): " << isnormal(2.0/0.0) << endl; }
输出
isnormal(5.23): 1 isnormal(0): 0 isnormal(inf): 0