nanl() Function with Example in C++

C++ nanl() function: Here, we are going to learn about the nanl() function with example of cmath header in C++ programming language.
Submitted by IncludeHelp, on May 20, 2020

C++ nanl() function

nanl() function is a library function of cmath header, it is used to get the NaN value of type long double. It accepts an argument (which is an implementation-specific C String – to get NaN value we have to pass an empty string), it returns NaN value of type long double.

Not-A-Number (NaN) values are used to check whether the value is an unidentified/non-representable or not? For example, the square root of a negative number is unidentified.

Syntax of nanl() function:

C++11:

    long double nanl (const char* tagp);

Parameter(s):

  • tagp – represents an implementation-specific C-String.

Return value:

The return type of this method is long double, it returns NaN value.

Example:

    Function call:
    nanl("");    
    
    Output:
    nan

C++ code to demonstrate the example of nanl() function

// C++ code to demonstrate the example of
// nanl() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    float nanValue;

    //generating generic NaN value
    //by passing an empty string
    nanValue = nanl("");

    //printing the value
    cout << "nanValue: " << nanValue << endl;

    return 0;
}

Output

nanValue: nan

Reference: C++ nanl() function



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.