Comment on Show HN: Optimizing Higher Order Functions with Hypothetical InversesparentComments−kazinator10yAnd if the behavior of overflow is to trap, then it should trap regardless of the order you add the numbers in.How come? Suppose A + B doesn't trap, and if T0 = A + B, then T0 + C doesn't trap. Why should (A + B) + C trap?−prodigal_erik10ySay you have a register whose range is -9..+9. (5-1)+5 doesn't trap but (5+5)-1 does.−kazinator10yI understand how to make an example of this; the question is why should (5-1)+5 trap, just because (5+5)-1 does.−rntz10yAh, good point! I was thinking of unsigned overflow, but signed overflow is a different matter, as pointed out elsewhere in this thread. I retract my statement about trapping overflow.
Comments
How come? Suppose A + B doesn't trap, and if T0 = A + B, then T0 + C doesn't trap. Why should (A + B) + C trap?
Say you have a register whose range is -9..+9. (5-1)+5 doesn't trap but (5+5)-1 does.
I understand how to make an example of this; the question is why should (5-1)+5 trap, just because (5+5)-1 does.
Ah, good point! I was thinking of unsigned overflow, but signed overflow is a different matter, as pointed out elsewhere in this thread. I retract my statement about trapping overflow.