libm: Make this work with overflow checks

Some math functions currently panic when compiled with overflow checks enabled (which is the default for dev builds). To fix this problem the Wrapping newtype and/or wrapping ops needs to be used in some parts of the implementations.

To test that this works with overflow checks enabled uncomment this line in ci/script.sh.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Just a fyi: I found a case that may need to use wrapping:

use libm::F64Ext; // adds methods to `f64`
pub fn sqrt(x: f64) -> f64 {
    x.sqrt()
}

Calling sqrt(2.0) in debug mode gives me: (using git master branch Oct 31, 2018)

thread 'math1' panicked at 'attempt to add with overflow', /home/mswanson/.cargo/git/checkouts/libm-62d0d08057355aaa/3559e70/src/math/sqrt.rs:180:18