Skip to content

Arguments mixed up in documentation of rem_euclid and div_euclid #128857

Closed
@fstecker

Description

@fstecker

Location

The documentation of rem_euclid and div_euclid for any signed integer type, e.g.: https://doc.rust-lang.org/stable/std/primitive.i32.html#method.rem_euclid

Summary

In the "Panics" section it says "This function will panic if rhs is 0 or if self is -1 and rhs is Self::MIN.", but I believe this is the wrong way around: the panic happens on MIN % -1, not on (-1) % MIN, as (correctly) explained in wrapping_rem_euclid and all other related functions.

Also, is there any situation where someone would want rem_euclid over wrapping_rem_euclid? Mathematically, MIN % -1 should really just be 0, that it panics is more of an implementation artifact (the corresponding division MIN / -1 overflows). Maybe it would be a good idea to add something like "If this is a problem, use wrapping_rem_euclid instead." to the documentation of rem_euclid? Though in most applications rhs will probably be positive anyway.

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions