Skip to content

Documentation for abs() on signed integers doesn't mention unsigned_abs() #124152

Closed

Description

@Architector4

Location

https://doc.rust-lang.org/std/primitive.i8.html#method.abs
https://doc.rust-lang.org/std/primitive.i16.html#method.abs
https://doc.rust-lang.org/std/primitive.i32.html#method.abs
https://doc.rust-lang.org/std/primitive.i64.html#method.abs
https://doc.rust-lang.org/std/primitive.i128.html#method.abs

Summary

The documentation mentions that the abs method could cause undesired behavior in case a MIN value of the type is passed.

It could use a mention of the unsigned_abs method after this, which can fit all possible return values at cost of converting the value to an unsigned integer instead, which may have been the behavior one wanted when looking for this function in the documentation.

It doesn't help that alphabetically unsigned_abs is sorted all the way down, while abs sits all the way up. A programmer could end up seeing only abs, and assume that they need to either specially handle MIN value, or use the immediately visible abs_diff function below that, with second parameter set to 0 to achieve the wanted effect. (the latter could use a clippy lint? lol)

Activity

  1. added
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    on Apr 19, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 19, 2024
  3. changed the title [-]Documentation for abs() on signed integer doesn't mention unsigned_abs()[/-] [+]Documentation for abs() on signed integers doesn't mention unsigned_abs()[/+] on Apr 19, 2024
  4. gurry commented on Apr 20, 2024

    @gurry
    Contributor

    @rustbot claim

  5. added a commit that references this issue on Apr 21, 2024
    24b8c54
  6. added a commit that references this issue on Apr 21, 2024
    197c6b3
  7. added
    T-libs-api[DEPRECATED; DO NOT USE]
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libs-api[DEPRECATED; DO NOT USE]

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions