Yol*_*ola 7 c++ floating-point compiler-errors nan
我需要获得浮动NaN和无穷大,但我不能使用这样的结构
0. / 0.
1. / 0.
Run Code Online (Sandbox Code Playgroud)
因为它会导致编译时间
错误C2124:除以或除以零
编辑,很高兴有答案我可以得到这个数字(每个+1),但有可能除以零?
jua*_*nza 17
您可以简单地返回NaN或无穷大,例如:
return std::numeric_limits<float>::quiet_NaN();
Run Code Online (Sandbox Code Playgroud)
要么
return std::numeric_limits<float>::infinity();
Run Code Online (Sandbox Code Playgroud)
见std::numeric_limits
,从报头<limits>
.