Skip to main content

midpoint

Function midpoint 

Source
fn midpoint(v: u64, w: u64) -> u64
Expand description

Overflow-safe midpoint between two distinct u64 values.

v + (w - v) / 2 never wraps: w - v is exact for w > v, and the halved difference is at most w - v, so the sum is at most w. Consecutive values collapse to the lower one, which still separates them (the lower value routes left, the higher routes right).