Skip to content

Specify that integer division by zero panics #1375

Description

@JanBeh

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.

Activity

  1. JanBeh commented on Jul 19, 2023

    @JanBeh
    Author

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

  2. mattheww commented on Jul 19, 2023

    @mattheww
    Contributor

    Oops, I will try again

  3. mattheww commented on Jul 19, 2023

    @mattheww
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions