google / wuffs

Wrangling Untrusted File Formats Safely
Other
4.07k stars 129 forks source link

A way to overflow or underflow on purpose #16

Closed mvdan closed 6 years ago

mvdan commented 6 years ago

Sometimes it is really wanted. All I could find in the repo is:

doc/wuffs-the-language.md:74:TODO: ignore-overflow ops, equivalent to Swift's `&+`.

I presume that means it is planned?

nigeltao commented 6 years ago

This is already implemented. x ~mod+ y will add while ignoring overflow. There's also the x ~mod+= y form that's analogous to the += operator. An example of its use is in std/adler32/common_adler32.wuffs. For that particular case, it's not as though the computation will actually overflow, but using ~mod+ instead of a plain + makes the proof checking easier.

It's a little verbose, but breaking it down: