# F64::midpoint

**URL:** <https://internals.rust-lang.org/t/f64-midpoint/23491>\
**Category:** libs\
**Created:** [September 4, 2025, 6:31pm UTC](https://internals.rust-lang.org/t/f64-midpoint/23491 "2025-09-04T18:31:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris00](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/chris00/32/8802_2.png) [@Chris00](https://internals.rust-lang.org/u/Chris00)\
**Post date:** [September 4, 2025, 6:31pm UTC](https://internals.rust-lang.org/t/f64-midpoint/23491/1 "2025-09-04T18:31:19Z")

</div>

Hi,

I was looking at the [`f64::midpoint`](https://doc.rust-lang.org/src/core/num/f64.rs.html#1010) implementation and was wondering why it does not use the paper “[How do you compute the midpoint of an interval?](https://hal.science/hal-00576641v2/document)“ ([HAL](https://hal.science/hal-00576641v2)) which, IMHO, behaves better.

Best,  
Christophe

---

<div class="post-metadata">

**Author:** ![Jules-Bertholet](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jules-bertholet/32/10671_2.png) [@Jules-Bertholet](https://internals.rust-lang.org/u/Jules-Bertholet)\
**Post date:** [September 5, 2025, 5:01am UTC](https://internals.rust-lang.org/t/f64-midpoint/23491/2 "2025-09-05T05:01:07Z")

</div>

IIUC, the implementation that paper proposes is:

```rust
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
    }
}

```

---

<div class="post-metadata">

**Author:** ![Jules-Bertholet](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jules-bertholet/32/10671_2.png) [@Jules-Bertholet](https://internals.rust-lang.org/u/Jules-Bertholet)\
**Post date:** [September 5, 2025, 5:20am UTC](https://internals.rust-lang.org/t/f64-midpoint/23491/3 "2025-09-05T05:20:31Z")

</div>

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](https://github.com/rust-lang/rust/issues/110840#issuecomment-2235000923)), I don't think it’s possible to get different results from the two?

---

<div class="post-metadata">

**Author:** ![Jules-Bertholet](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jules-bertholet/32/10671_2.png) [@Jules-Bertholet](https://internals.rust-lang.org/u/Jules-Bertholet)\
**Post date:** [September 5, 2025, 5:42am UTC](https://internals.rust-lang.org/t/f64-midpoint/23491/4 "2025-09-05T05:42:04Z")

</div>

Actually, I think those checks don't make a difference. I am pretty sure the implementations give identical results

Edit: [Simplify `{f16, f32, f64, f128}::midpoint()` by Jules-Bertholet · Pull Request #146225 · rust-lang/rust · GitHub](https://github.com/rust-lang/rust/pull/146225)
