nan c++ example
C++
#include <iostream>
#include <cmath>
using namespace std;
// main() section
int main()
{
double nanValue;
//generating generic NaN value
//by passing an empty string
nanValue = nan("");
//printing the value
cout<<"nanValue: "<<nanValue<<endl;
return 0;
}What is NaN ?
NaN, acronym for “Not a Number” is an exception
which usually occurs in the caseswhen an expression
results in a number that can’t be represented.
For example square root of negative numbers.
// C++ code to demonstrate NaN exception
#include<iostream>
#include<cmath> // for sqrt()
using namespace std;
int main()
{
float a = 2, b = -2;
// Prints the number (1.41421)
cout << sqrt(a) << endl;
// Prints "nan" exception
// sqrt(-2) is complex number
cout << sqrt(b) << endl;
return 0;
}
Output:
1.41421
-nan
Also in C++:
- Title
- c++ evaluate expression
- Category
- C++
- Title
- how to compare lower case character to uppercase cpp
- Category
- C++
- Title
- container class in c++
- Category
- C++
- Title
- c++ menu selection with arrow keys
- Category
- C++
- Title
- Html tab
- Category
- C++
- Title
- arduino delay millis
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- passing array to function in c++
- Category
- C++
- Title
- c++ initialization list
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- variabili in c++
- Category
- C++
- Title
- C++ Student::Student()
- Category
- C++
- Title
- c++ max of array
- Category
- C++
- Title
- variadic templates
- Category
- C++
- Title
- c++ vector lower_bound index
- Category
- C++
- Title
- how to read a comma delimited file into an array c++
- Category
- C++
- Title
- nth_element c++
- Category
- C++
- Title
- c++ reset stream
- Category
- C++
- Title
- max three values c++
- Category
- C++
- Title
- cpp pi from acos
- Category
- C++
- Title
- programa para saber si un numero es primo
- Category
- C++
- Title
- c++ empty stream
- Category
- C++
- Title
- range of int
- Category
- C++
- Title
- Merge k sorted linked lists and return it as one sorted list.
- Category
- C++
- Title
- strchr function in c++
- Category
- C++
- Title
- c++ how to add something at the start of a vector
- Category
- C++
- Title
- lambda operator in c++
- Category
- C++
- Title
- first prime numbers
- Category
- C++
- Title
- primeros numeros primos
- Category
- C++
- Title
- pointer related problems dangling/wild pointers c++
- Category
- C++
- Title
- pass vector by reference c++
- Category
- C++
- Title
- c++ loop through int array
- Category
- C++
- Title
- remove value from vector c++
- Category
- C++
- Title
- double to string c++
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- print matrix c++
- Category
- C++
- Title
- mkdir c++
- Category
- C++
- Title
- Runtime Error: Runtime ErrorAbort signal from abort(3) (SIGABRT)
- Category
- C++
- Title
- c++ clear stream
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- inconsequential meaning
- Category
- C++
- Title
- c++ set add element
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- how to convert a string to a double c++
- Category
- C++
- Title
- c++ remove item from list
- Category
- C++
- Title
- first fit algorithm
- Category
- C++
- Title
- how to find the index of an element in a vector c++
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- C++ string format ctime
- Category
- C++
- Title
- char **
- Category
- C++
- Title
- c++ remove element from vector
- Category
- C++
- Title
- how to print to the serial monitor arduino
- Category
- C++
- Title
- knapsack
- Category
- C++
- Title
- passing array to function c++ pointer
- Category
- C++
- Title
- c++ delete dynamically allocated array
- Category
- C++
- Title
- c++ string to vector int
- Category
- C++
- Title
- c++ functions
- Category
- C++
- Title
- stoi c++
- Category
- C++
- Title
- c++ do while loop
- Category
- C++
- Title
- c++ operator overloading not equal
- Category
- C++
- Title
- how to print 5 precision float in c++
- Category
- C++
- Title
- c++ modulo make it give only positive numbers
- Category
- C++
- Title
- struct c++
- Category
- C++
- Title
- count a character in a string c++
- Category
- C++
- Title
- power c++
- Category
- C++
- Title
- length of 2d array c++
- Category
- C++
- Title
- what is a header in c++
- Category
- C++
- Title
- get elements of 2d array c++
- Category
- C++
- Title
- C++ int to char*
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- binary serach in c++
- Category
- C++
- Title
- calculate sum in c++
- Category
- C++
- Title
- multiset c++
- Category
- C++
- Title
- string length c++
- Category
- C++
- Title
- how to return a vector c++
- Category
- C++
- Title
- c++ char print fixed
- Category
- C++
- Title
- worker class c++
- Category
- C++
- Title
- how to extract substring from string in c++
- Category
- C++
- Title
- c++ rainbow text
- Category
- C++
- Title
- cpp loop through object
- Category
- C++
- Title
- how to import getline in c++
- Category
- C++
- Title
- convert entire string to lowercase c++
- Category
- C++
- Title
- -> cpp
- Category
- C++
- Title
- ternary operator c++
- Category
- C++
- Title
- c++ declare char
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- visual studio 2019 c++ tutorial project
- Category
- C++
- Title
- error: redefinition of ‘class Customer’
- Category
- C++
- Title
- Find the duplicate in an array of N integers.
- Category
- C++
- Title
- ue4 c++ array
- Category
- C++
- Title
- getline not working c++
- Category
- C++
- Title
- how to hide ui elements unity
- Category
- C++
- Title
- how to compare two strings lexicographically in c++
- Category
- C++
- Title
- how to input multiple lines of a file in c++
- Category
- C++
- Title
- how to open an input file in c++
- Category
- C++
- Title
- if esle in c++
- Category
- C++
- Title
- initialize 2d array c++
- Category
- C++
- Title
- including cpp header file in c++
- Category
- C++
- Title
- C++ sfinae
- Category
- C++
- Title
- how to convert qt string to string
- Category
- C++