3 ms·
I'm tempted to suggest (low / 2) + (high / 2) but then I have to think about rounding error. Ugh. I guess you could write a bunch of nested `if`s to handl
by rntz 9y ago
I'm tempted to suggest
(low / 2) + (high / 2)
but then I have to think about rounding error. Ugh. I guess you could write a bunch of nested `if`s to handle the parity errors, assuming you know how your language rounds when dividing negative numbers. (I wouldn't be surprised if C leaves that "implementation-defined".) If you're really searching an arbitrary range, maybe just use bigints. Then at least you can stop worrying about overflow altogether.