Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ln panics on Decimal::ZERO #398

Closed
SebRollen opened this issue Jun 18, 2021 · 0 comments · Fixed by #399
Closed

ln panics on Decimal::ZERO #398

SebRollen opened this issue Jun 18, 2021 · 0 comments · Fixed by #399

Comments

@SebRollen
Copy link
Contributor

MWE:

use rust_decimal::prelude::*;

fn main() {
    Decimal::ZERO.ln();
}
thread 'main' panicked at 'Division by zero', /Users/rollen/.cargo/registry/src/github.com-1ecc6299db9ec823/rust_decimal-1.14.2/src/decimal.rs:1972:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Of course taking the log of zero should yield some sort of error, but so should taking the log of negative numbers most likely, and for those the result is set to zero.

Decimal::new(-1, 0).ln() == Decimal::ZERO //true

The easiest fix might be to extend the predicate on this line to also check for *self != Decimal::ZERO

if self.is_sign_positive() {
. Happy to open a PR for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant