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

integer division by zero isn't caught #1974

Closed
bob-carpenter opened this issue Jul 25, 2016 · 4 comments
Closed

integer division by zero isn't caught #1974

bob-carpenter opened this issue Jul 25, 2016 · 4 comments
Assignees
Labels
Milestone

Comments

@bob-carpenter
Copy link
Contributor

Summary:

Integer divide by zero throws an uncaught exception.

Description:

Running this crashes RStan:

library(rstan)

mc <- '
parameters {real theta;}
model {
  target += 1/0;
}
'
sm <- stan_model(model_code = mc)
post <- sampling(sm, show_messages = FALSE)

I'm reporting in Stan because in the command refactor, we'll be catching this in Stan itself.

Reproducible Steps:

See above.

Current Output:

Crashes with `Floating point exception: 8

Expected Output:

Informative error message.

Additional Information:

Originally reported by @davharris on RStan tracker in issue stan-dev/rstan#316

Current Version:

v2.10.0

@bob-carpenter bob-carpenter added this to the v2.10.0++ milestone Jul 25, 2016
@syclik
Copy link
Member

syclik commented Jul 25, 2016

The problem is in math:
https://github.com/stan-dev/math/blob/develop/stan/math/prim/scal/fun/divide.hpp#L25

This line has undefined behavior:

return std::div(x, y).quot;

I didn't realize it threw an exception outside of the stdexcept types. Any suggestions on how to fix this call?

@bob-carpenter
Copy link
Contributor Author

Overload for int and check for zero in denominator?

Do you know what it does throw? If so, you could catch
and rethrow.

  • Bob

On Jul 25, 2016, at 5:43 PM, Daniel Lee notifications@github.com wrote:

The problem is in math:
https://github.com/stan-dev/math/blob/develop/stan/math/prim/scal/fun/divide.hpp#L25

This line has undefined behavior:

return std::div(x, y).quot;

I didn't realize it threw an exception outside of the stdexcept types. Any suggestions on how to fix this call?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@syclik
Copy link
Member

syclik commented Jul 25, 2016

The internet is saying check for 0, so that's the fix I'll apply.

On Jul 25, 2016, at 5:57 PM, Bob Carpenter notifications@github.com wrote:

Overload for int and check for zero in denominator?

Do you know what it does throw? If so, you could catch
and rethrow.

  • Bob

On Jul 25, 2016, at 5:43 PM, Daniel Lee notifications@github.com wrote:

The problem is in math:
https://github.com/stan-dev/math/blob/develop/stan/math/prim/scal/fun/divide.hpp#L25

This line has undefined behavior:

return std::div(x, y).quot;

I didn't realize it threw an exception outside of the stdexcept types. Any suggestions on how to fix this call?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.


You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or mute the thread.

@syclik
Copy link
Member

syclik commented Jul 26, 2016

This issue was moved to stan-dev/math#321

@syclik syclik closed this as completed Jul 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants