Re:Fast midpoint between two integers without overflow
by a1369209993 on Wednesday December 07, 2022 @05:05PM
(#33900976)
Note that this can equivalently[0] (and more readably) be written as `(a/2) + (b/2) + (a&b&1)`.
0: Assuming your language rounds integer division and modulo correctly, ie that `i%array_len` is reliably a valid array index. C has problems here when i (respectively: a or b) is signed, but that doesn't matter in the sensible case, where you always index everything with size_t.
0: Assuming your language rounds integer division and modulo correctly, ie that `i%array_len` is reliably a valid array index. C has problems here when i (respectively: a or b) is signed, but that doesn't matter in the sensible case, where you always index everything with size_t.