isfinite函数_isfinite()函数以及C ++中的示例

isfinite函数

C ++ isfinite()函数 (C++ isfinite() function)

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 ++代码演示isfinite()函数的示例 (C++ code to demonstrate the example of isfinite() function)

// 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): 1
isfinite(0.0/0.0): 0
isfinite(0.0/1.0): 1
isfinite(1.0/0.0): 0
10 is a finite value.
inf is not a finite value.

Reference: C++ isfinite() function

参考: C ++ isfinite()函数

翻译自: https://www.includehelp.com/cpp-tutorial/isfinite-function-with-example.aspx

isfinite函数

你可能感兴趣的:(c++,python,java,javascript,php,ViewUI)