37 ms·
This one has a serious flaw: http://dflund.se/~john_e/gems/gem0032.html http://dflund.se/~john_e/gems/gem0032.html The neg (two's complement) of 0x80000000 is
by tasty_freeze 11y ago
This one has a serious flaw:
http://dflund.se/~john_e/gems/gem0032.html http://dflund.se/~john_e/gems/gem0032.html
The neg (two's complement) of 0x80000000 is 0x80000000. Thus his trick results in an infinite loop for the most negative value.
- mattst88 11y agoIndeed. The x86 equivalent gem (http://dflund.se/~john_e/gems/gem0001.html http://dflund.se/~john_e/gems/gem0001.html) makes a point to note that. Odd that it's not mentioned on the m68k page. For what it's worth, my copy of the C11 spec says The abs, labs, and llabs functions compute the absolute value of an integer j. If the result cannot be represented, the behavior is undefined. 304) 304) The absolute value of the most negative number cannot be represented in two’s complement.