如何实现下面的 Action ?
if( boost::math:: +is_inf (x) )
x= max double;
else if( boost::math:: -is_inf (x) )
x= min double;
我想保留 x 的符号。
最佳答案
这里关键是,大家可以比较+inf
或 -inf
到 0 <
和 >
,所以测试标志非常容易。
if(std::isinf(x))
{
if(x>0)
x = std::numeric_limits<double>::max();
else
x = -std::numeric_limits<double>::max();
}
如果您使用的是 c++11,则无需 boost
关于C++将无穷大转换为最大值并将-inf转换为最小值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33853392/