What is nanl() in C/C++?
The nanl function removes the NaN(not-a-number) value from the input string.
It returns the NaN value of type long double.
Library for C++
#include<cmath>
Library for C
#include<math.h>
Syntax
long double nanl (const char* str);
Parameters
str - a string value
Return Value
It returns a NaN value which is in long double.
Code
#include <iostream>#include <cmath>#include <cstring>using namespace std;int main(){float nanValue;//generating generic NaN value by passing an empty stringnanValue = nanl("");cout << "nanValue: " << nanValue << endl;float nanValue1;nanValue1 = nanl("12343");cout << "nanValue: " << nanValue1 << endl;float nanValue2;nanValue2 = nanl("abc");cout << "nanValue: " << nanValue2 << endl;return 0;}
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved