Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That doesn't work when both are odd. For example, for x=1 and y=3 this gives 1 instead of 2.


1/2 + 3/2 + 1 = 0 + 1 + 1 = 2


Your final +1 is not in the expression by OP. You can get it by taking the correction term (x & y & 1) as mentioned in another comment.


woops, misread the indent-depth of the posts as reply, not to the same parent.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: