小编per*_*son的帖子

如何处理浮点溢出?

如果某个值发生浮点溢出,我想将其设置为零,就像这样...

m_speed += val;
if ( m_speed > numeric_limits<float>::max()) { // This might not even work, since some impls will wraparound after previous line
  m_speed = 0.f
}
Run Code Online (Sandbox Code Playgroud)

但一旦val添加m_speed,就已经发生了溢出(并且我假设如果这样做,也会发生相同的问题if (( m_speed + val ) > ..)。)

如何检查以确保不会发生溢出而发生溢出?

c++ floating-point error-handling overflow

4
推荐指数
1
解决办法
1715
查看次数

标签 统计

c++ ×1

error-handling ×1

floating-point ×1

overflow ×1