Skip to content

Comment on Show HN: Optimizing Higher Order Functions with Hypothetical Inversesparent

Comments

And 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?

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.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.