How to generate NaN float value in C++

2 Answers

0 votes
#include <iostream>
#include <cmath>

int main()
{
    float f;
    
    f = nanf("");
    
    std::cout << f;
}




/*
run:

nan

*/

 



answered Jul 30, 2022 by avibootz
0 votes
#include <iostream>
#include <cmath>

int main()
{
    float f = NAN;
    
    std::cout << f;
}




/*
run:

nan

*/

 



answered Jul 30, 2022 by avibootz

Related questions

2 answers 146 views
146 views asked Jul 30, 2022 by avibootz
2 answers 147 views
1 answer 126 views
2 answers 136 views
1 answer 165 views
...