DEV Community

Discussion on: Notes on algorithms

Collapse
 
mah_khalafallah profile image
Mahmoud Khalafallah

I didn't get avoid overflow part

Collapse
 
emilie_gl profile image
Emilie Gervais • Edited

To prevent integer overflow for large numbers which could end up being too big to fit the integer's storage space.
en.wikipedia.org/wiki/Integer_over...
fresh2refresh.com/c-programming/c-...

Collapse
 
mah_khalafallah profile image
Mahmoud Khalafallah

Aha, I see
So we get the difference first and divide it by 2 then add it to the start.
instead of adding the start and the end.
But why we didn't do the same with the js example ?!

Thread Thread
 
emilie_gl profile image
Emilie Gervais

To highlight both possibilities? You don't always have to worry about overflow; When you do, it's nice to know there's a simple solution. These are just notes.