Skip to content

Use cube root function lint #9201

@leonardo-m

Description

@leonardo-m

What it does

The lint suggest to replace a FP::powf() call with a different method call.

Lint Name

use_cube_root_function

Category

perf

Advantage

It's more precise, shorter and simpler.

Drawbacks

None, I think.

Example

#![warn(clippy::all)]
#![warn(clippy::nursery)]
#![warn(clippy::pedantic)]
fn main() {
    println!("{}", 1.5_f64.powf(1.0 / 3.0));
}

Could be written as:

#![warn(clippy::all)]
#![warn(clippy::nursery)]
#![warn(clippy::pedantic)]
fn main() {
    println!("{}", 1.5_f64.cbrt());
}

Also note that they output slightly different results. cbrt is more precise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions