mcarton / rust-herbie-lint

A rustc plugin to check for numerical instability
Mozilla Public License 2.0
173 stars 4 forks source link

Herbie is advising the use of log1p, which doesn't exist #4

Closed urschrei closed 8 years ago

urschrei commented 8 years ago

I've just run Herbie on some floating-point operations using Nightly, and I get this:

src/lib.rs:232:67: 232:85 warning: Numerically unstable expression, #[warn(herbie)] on by default
src/lib.rs:232     let M2 = (3. * n + 3. * n.powi(2) + (21. / 8.) * n.powi(3)) * (lat - lat0).sin() *
src/lib.rs:232:67: 232:85 help: Try this
src/lib.rs:        let M2 = (3. * n + 3. * n.powi(2) + (21. / 8.) * n.powi(3)) * ((lat.sin() * lat0.cos()) - (lat.cos() * lat0.sin())).log1p().expm1() *

Which is great! But there's no log1p function in Rust as far as I can see…it exists in the GSL crate (which is a wrapper around GNU GSL), but that's not obvious:

src/lib.rs:232:121: 232:128 error: no method named `log1p` found for type `f64` in the current scope
urschrei commented 8 years ago

Looking at this a little more closely, it seems that the functions do exist, but they're named differently: log1p is ln_1p (it's actually an unsafe call to cmath::log1p) in f64. Similarly, exp_m1 is a call to cmath::expm1. I assume that Herbie.db has references to standard function names, and these were changed in std::f64 for some reason…

mcarton commented 8 years ago

Thanks for the report. This should be fixed in 1.0.3.

urschrei commented 8 years ago

Just tried it, and works as expected. Thanks! ✨

mcarton commented 8 years ago

If you have any other problem or suggestion, don’t hesitate :smile: