NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
Integer Overflow Checking Cost (danluu.com)
tcfhgj 2 hours ago [-]
Definitely cheaper than using Electron I would say
mayoff 3 hours 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).

qayxc 1 hours ago [-]
> 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).

Never make guesses based on a particular programming language. In Apple's own C documentation (https://developer.apple.com/documentation/xcode/integer-over...) it is stated that "Overflows result in undefined behavior." and enabling wrapping behaviour "may adversely impact performance", indicating that overflow detection is in fact not "virtually free".

saagarjha 1 hours ago [-]
Code size (and branch table entries) are not free, of course. The other thing to note is that trapping operators often need to trap precisely which can lead to missed optimizations.
gnabgib 2 days ago [-]
2014 (probably? Or 2008. Old and no date) Previously (166 points, 2014, 107 comments) https://news.ycombinator.com/item?id=8765714
zahlman 2 days ago [-]
Resubmitting it seems timely, given recent Linux kernel news (e.g. https://lwn.net/Articles/1065889/).
aw1621107 4 hours ago [-]
The archive says "12/14", so 2014 seems about right.
ardline 4 hours ago [-]
[flagged]
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 11:12:49 GMT+0000 (Coordinated Universal Time) with Vercel.