Skip to content

Detect usage of custom floating-point abs implementation #5224

Closed
@krishna-veerareddy

Description

@krishna-veerareddy

Detect usage of

if a < 0.0 { // or a.is_sign_negative()
    -a
} else {
    a
}

and

if a > 0.0 { // or a.is_sign_positive()
    a
} else {
    -a
}

and suggest usage of abs instead

a.abs()

Using abs is more efficient, handles more cases and is more succinct than using the if/else block so this lint could go under the suboptimal_flops lint. If this seems like an obvious thing and isn't worth the check then I'd be happy to close it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-complexityLint: Belongs in the complexity lint groupgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions