@@ -434,17 +434,15 @@ loop iteration, causing different outcomes depending on which iteration the
434
434
failure occurs in. The compiler can unroll the loop, but it cannot
435
435
algebraically reduce multiple operations into fewer equivalent operations.
436
436
437
- Saturated integer arithmetic is just one example of a really poor choice of
438
- language semantics that completely prevents effective performance
439
- optimization. There are many things that are difficult about C programming,
440
- but integer overflow is *not * one of them – especially on 64-bit systems. If
441
- my integers really might get bigger than 2^63-1, I can easily predict that. Am
442
- I looping over a number of actual things that are stored in the computer? Then
443
- it's not going to get that big. This is guaranteed, since I don't have that
444
- much memory. Am I counting things that occur in the real world? Unless they're
445
- grains of sand or atoms in the universe, 2^63-1 is going to be plenty big. Am
446
- I computing a factorial? Then sure, they might get that big – I should use a
447
- ``BigInt ``. See? Easy to distinguish.
437
+ The most reasonable alternative to having integer arithmetic silently overflow
438
+ is to do checked arithmetic everywhere, raising errors when adds, subtracts,
439
+ and multiplies overflow, producing values that are not value-correct. In this
440
+ [blog post](http://danluu.com/integer-overflow/), Dan Luu analyzes this and
441
+ finds that rather than the trivial cost that this approach should in theory
442
+ have, it ends up having a substantial cost due to compilers (LLVM and GCC)
443
+ not gracefully optimizing around the added overflow checks. If this improves
444
+ in the future, we could consider defaulting to checked integer arithmetic in
445
+ Julia, but for now, we have to live with the possibility of overflow.
448
446
449
447
450
448
.. _man-abstract-fields :
0 commit comments