本文共 2077 字,大约阅读时间需要 6 分钟。
isfinite函数
isfinite() function is a library function of cmath header, it is used to check whether the given value is a finite value or not? It accepts a value (float, double or long double) and returns 1 if the value is finite; 0, otherwise.
isfinite()函数是cmath标头的库函数,用于检查给定值是否为有限值? 它接受一个值( float , double或long double ),如果该值是有限的,则返回1;否则,返回1。 0,否则。
Syntax of isfinite() function:
isfinite()函数的语法:
In C99, it has been implemented as a macro,
在C99中,它已实现为宏,
macro isfinite(x)
In C++11, it has been implemented as a function,
在C ++ 11中,它已作为函数实现,
bool isfinite (float x); bool isfinite (double x); bool isfinite (long double x);
Parameter(s):
参数:
x – represents a value to be checked as finite value.
x –表示要检查为有限值的值。
Return value:
返回值:
The returns type of this function is bool, it returns 1 if x is a finite value; 0, otherwise.
该函数的返回类型为bool ,如果x为有限值,则返回1;否则,返回1。 0,否则。
Example:
例:
Input: float x = 10.0f; Function call: isfinite(x); Output: 1
// C++ code to demonstrate the example of// isfinite() function#include#include using namespace std;int main(){ cout << "isfinite(0.0): " << isfinite(0.0) << endl; cout << "isfinite(0.0/0.0): " << isfinite(0.0 / 0.0) << endl; cout << "isfinite(0.0/1.0): " << isfinite(0.0 / 1.0) << endl; cout << "isfinite(1.0/0.0): " << isfinite(1.0 / 0.0) << endl; float x = 10.0f; // checking finite value using the condition if (isfinite(x)) { cout << x << " is a finite value." << endl; } else { cout << x << " is not a finite value." << endl; } x = 10.0f / 0.0f; if (isfinite(x)) { cout << x << " is a finite value." << endl; } else { cout << x << " is not a finite value." << endl; } return 0;}
Output
输出量
isfinite(0.0): 1isfinite(0.0/0.0): 0isfinite(0.0/1.0): 1isfinite(1.0/0.0): 010 is a finite value.inf is not a finite value.
Reference:
参考:
翻译自:
isfinite函数
转载地址:http://ehxzd.baihongyu.com/