Closed
Description
What it does
Detects manual implementations of these functions and suggests replacing them with a call to that function.
Lint Name
float_manual_finite/float_manual_infinite
Category
style, pedantic
Advantage
- easier to read
- less code to work with
- could be faster than the original code see source of
is_infinite
, which suggests some future optimizations
Drawbacks
- maybe changes the meaning of the code?
Example
fn double(float: f32) -> f32 {
if float == f32::INFINITY || float == f32::NEG_INFINITY {
println!("is infinite");
}
float * 2.0
}
fn main() {
dbg!(double(6.63E-34));
}
Could be written as:
fn double(float: f32) -> f32 {
if float.is_infinite() {
println!("is infinite");
}
float * 2.0
}
fn main() {
dbg!(double(6.63E-34));
}
fn double(float: f32) -> f32 {
assert!(float != f32::INFINITY && float != f32::NEG_INFINITY);
float * 2.0
}
fn main() {
dbg!(double(6.63E-34));
}
Could be written as:
fn double(float: f32) -> f32 {
assert!(float.is_finite());
float * 2.0
}
fn main() {
dbg!(double(6.63E-34));
}