Integer Overflow Checking Cost
19 points by iwsk 3 days ago | 4 comments

mayoff 4 minutes ago
In Swift (Apple’s C++ successor), the normal operators (`+`, `-`, `*`) trap on overflow for integer types. If you want twos complement wrapping, you can use `&+`, `&-`, and `&*`.

Given that Apple has been making its own CPU cores for years now, I suspect overflowing checking on Apple CPUs is virtually free (aside from code size).

reply
gnabgib 3 days ago
2014 (probably? Or 2008. Old and no date) Previously (166 points, 2014, 107 comments) https://news.ycombinator.com/item?id=8765714
reply
zahlman 3 days ago
Resubmitting it seems timely, given recent Linux kernel news (e.g. https://lwn.net/Articles/1065889/).
reply
aw1621107 2 hours ago
The archive says "12/14", so 2014 seems about right.
reply
ardline 2 hours ago
[flagged]
reply