Re:How do you compute the midpoint of an interval? (2014) [pdf]
by fhars on Friday March 29, 2019 @02:33AM
(#19519594)
Similar things are relevant for calculations with integers (like array indexes), if you haven‘t yet, read this classic post about it: https://ai.googleblog.com/2006/06/extra-extra-read-all-about... (reader mode makes it accessible on iPhones, why don‘t people test their layouts with common browsers?).
[ Parent
| on HN ]
Re:How do you compute the midpoint of an interval? (2014) [pdf]
by Sean1708 on Friday March 29, 2019 @10:14AM
(#19521846)
In C and C++ (where you don't have the >>> operator), you can do this:
6: mid = ((unsigned int)low + (unsigned int)high)) >> 1;
Since you're casting to unsigned int anyway, can't you just use / 2?
Re:How do you compute the midpoint of an interval? (2014) [pdf]
by kevinventullo on Friday March 29, 2019 @10:46AM
(#19522125)
Yeah, I believe those compile to the same thing for unsigned ints. You can confirm using godbolt.