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

Specify that integer division by zero panics #1375

Closed
JanBeh opened this issue Jun 29, 2023 · 3 comments · Fixed by #1382
Closed

Specify that integer division by zero panics #1375

JanBeh opened this issue Jun 29, 2023 · 3 comments · Fixed by #1382
Labels
A-expressions Area: Expressions

Comments

@JanBeh
Copy link

JanBeh commented Jun 29, 2023

While there is a section on overflow behavior, which discusses that integer overflows will trigger a panic in debug mode, the section "Arithmetic and Logical Binary Operators" doesn't specify what happens when an integer division by zero is encountered.

There is a note in the standard library documentation regarding the impl std::ops::Div<i32> for i32 (source), which states that a division by zero panics (irregardless of whether being in debug mode or not):

This operation will panic if other == 0 or the division results in overflow.

However, as discussed on URLO, this only seems to guarantee that e.g. 1.div(0) panics, but it (formally) doesn't make any statement regarding the primitive operation 1 / 0.

The section "Arithmetic and Logical Binary Operators" should be extended and state that integer division by zero panics (irregardless of whether being compiled with debug mode).

Maybe, the behavior on overflow due to signed integer division should also be documented in the reference (which, according to std::ops::Div, is also guaranteed to panic). edit: This is already documented in the "Overflow" subsection.

@JanBeh
Copy link
Author

JanBeh commented Jul 19, 2023

Doesn't seem to have been solved properly, see #1382 (comment).

@mattheww
Copy link
Contributor

Oops, I will try again

@mattheww
Copy link
Contributor

The PR title was bad, but I think what was committed isn't outright incorrect because the † is in the column headed 'Integer' and not in the column headed 'Floating point'.

But it would be clearer to say "integer" in the text like in the note about rounding to zero.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-expressions Area: Expressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants