Hacker News new | ask | show | jobs
by zem 911 days ago
this is a very interesting feature:

8<------------------

If adding a value to a type where the result exceeds the type's maximum capacity in either the positive or negative direction, the type must remain at its previous value.

Note

This means that if you add 1 to an int at value 2^31, it will stay at 2^31. This is also called "saturating" a value.

1 comments

The proposed mechanism is only equivalent to a saturating add when you add 1
oh right, a true saturating add would set it to MAX_INT rather than the previous value!