Hi,
I was looking at the f64::midpoint
implementation and was wondering why it does not use the paper “How do you compute the midpoint of an interval?“ (HAL) which, IMHO, behaves better.
Best,
Christophe
Hi,
I was looking at the f64::midpoint
implementation and was wondering why it does not use the paper “How do you compute the midpoint of an interval?“ (HAL) which, IMHO, behaves better.
Best,
Christophe
IIUC, the implementation that paper proposes is:
pub const fn midpoint(self, other: f64) -> f64 {
let result = (self + other) / 2;
if !result.is_finite() && self.is_finite() && other.is_finite() {
(self / 2) + (other / 2)
} else {
result
}
}
Other than the underflow checks in the std implementation (which seem suspicious, as noted in Tracking Issue for num_midpoint · Issue #110840 · rust-lang/rust · GitHub), I don't think it’s possible to get different results from the two?
Actually, I think those checks don't make a difference. I am pretty sure the implementations give identical results