Skip to content

Specify that integer division by zero panics #1375

Closed
@JanBeh

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.

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