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

Incorrect value for the exponential function of (-1) #327

Closed
jonahpelfrey opened this issue Mar 24, 2021 · 0 comments · Fixed by #339
Closed

Incorrect value for the exponential function of (-1) #327

jonahpelfrey opened this issue Mar 24, 2021 · 0 comments · Fixed by #339
Assignees
Milestone

Comments

@jonahpelfrey
Copy link

jonahpelfrey commented Mar 24, 2021

I'm using rust_decimal to implement a Monte Carlo simulation that requires the use of the exponential function (e^x).

While debugging values in the Monte Carlo, I ran into a case where the input to Decimal::exp() was -1, and the output was zero.

Simplified code:

use rust_decimal::prelude::*;

fn main() {
  let decimal = Decimal::from_str("-1").unwrap();
  let value = decimal.exp();
  println!("Value: {:?}", value);
  // Value: 0
}

Wolfram alpha: 0.36787944117
https://www.wolframalpha.com/input/?i=e%5E-1

Any ideas on what might be causing the approximation to be incorrect?

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.

2 participants