Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
sbrother
· 2y ago · 0 comments
That is mind blowing, but it’s not immediately obvious to me that it’s equivalent for n > sqrt(INT_MAX). Is it? And if so, is the compiler somehow smart enough to know that?
Comments
[–]
marin049
2y ago
Integer overflow is actually undefined behaviour thus the compiler is free to assume it doesn't happen.
[–]
xigoi
2y ago
If you assume two’s complement arithmetic, then this is always equivalent because you’re basically just calculating the answer in a modular ring.