pretty-algorithms icon indicating copy to clipboard operation
pretty-algorithms copied to clipboard

can the sum overflow?

Open dilbert-ro opened this issue 8 years ago • 2 comments

https://github.com/jiayihu/pretty-algorithms/blob/e97dcb78129896b7dc7eb6ec22eba6dd20255bcd/algorithms/search/binary-search/binary-search.ts#L12

dilbert-ro avatar Aug 19 '17 14:08 dilbert-ro

It's very unlikely that you have numbers so huge to overflow , especially on the client

jiayihu avatar Aug 19 '17 14:08 jiayihu

You can use (start + ((end - start) / 2) to avoid the overflow, in case that happens.

utkarshbhatt12 avatar Aug 23 '17 14:08 utkarshbhatt12