4 ms·
Generally you'll be doing this anyways (as you'll be storing it with a bit to tag if it is a pointer). However, it is... interesting... that a language that is
by TheLoneWolfling 12y ago
Generally you'll be doing this anyways (as you'll be storing it with a bit to tag if it is a pointer).
However, it is... interesting... that a language that is so low-level does not have any simple construct for doing this, especially seeing how trivial it is in x86 assembly (add the numbers, then check the overflow flag).
And saying "just don't used signed arithmetic" misses the point. If a "general-purpose" programming language cannot do something that is trivial in the next layer down, and that occurs as commonly as wanting to do something if there would be an overflow, I am inclined to blame the language, not the coder.
- RaleyField 12y ago> especially seeing how trivial it is in x86 assembly (add the numbers, then check the overflow flag) I'm no expert, especially not on modern x86 processors or compilers for them, but I suspect it isn't so trivial as scattering such instructions may affects branch predictor tables and indirectly degrade performance in other parts of code.
- TheLoneWolfling 12y agoYou require one branch regardless, and the trivial version is one branch, i.e. already at the minimum amount of branches.