如何在 C++ 中返回 NaN
从 C++11 开始,返回 NaN 作为 double 就像这样简单
return_nan_double.cpp
#include <cmath>
return std::nan("");如果你想返回 float 使用
return_nan_float.cpp
#include <cmath>
return std::nanf("");在极少数 long double 的情况下使用
return_nan_longdouble.cpp
#include <cmath>
return std::nan("");Check out similar posts by category:
C/C++
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow