What it does
Add a lint censuring f32::round and f64::round in favour of the corresponding round_ties_even function. Currently, one can achieve this with
disallowed-methods = [
{ path = "f32::round", reason = "round_ties_even is less biased and faster"},
{ path = "f64::round", reason = "round_ties_even is less biased and faster"},
]
but I think it would be valuable as a separate lint. (Possibly it could be part of in suboptimal_flops, but there's talk about splitting that up already.
For some context, see this issue and this pull request and its tracking issue.
Advantage
- It's faster.
- It doesn't introduce an unnecessary positive bias.
- It is the IEEE-754 default behaviour.
Drawbacks
round_ties_even is a longer name that's harder to read.
round matches more closely the behaviour of the method taught to young children.
- It introduces a bias towards even numbers.
Example
fn print_num(x: f32) {
println!("{}", x.round());
}
Could be written as:
fn print_num(x: f32) {
println!("{}", x.round_ties_even());
}
What it does
Add a lint censuring
f32::roundandf64::roundin favour of the correspondinground_ties_evenfunction. Currently, one can achieve this withbut I think it would be valuable as a separate lint. (Possibly it could be part of in
suboptimal_flops, but there's talk about splitting that up already.For some context, see this issue and this pull request and its tracking issue.
Advantage
Drawbacks
round_ties_evenis a longer name that's harder to read.roundmatches more closely the behaviour of the method taught to young children.Example
Could be written as: