4 ms·
Arbitrary-precision integers are not that slow if they're implemented the way most Lisp implementations do it. For a strongly-typed language, you would need on
by ScottBurson 9y ago
Arbitrary-precision integers are not that slow if they're implemented the way most Lisp implementations do it. For a strongly-typed language, you would need only one tag bit: if the low-order bit is 0, then the remaining bits of a pointer-sized word, shifted right 1 bit, are the value; no heap storage or indirection is required, and addition and subtraction require no fixup afterwards as long as there was no overflow. Only if the low-order bit of an operand is 1, or if there's overflow, do you have to trap out to the general case which handles heap allocation.
Yes, this is slower than ordinary fixed-width integer arithmetic, as a couple of conditional branches are required, but it's nowhere near the price of heap-allocating every integer.
- noir_lord 9y agoThat's clever, stuff like that which is so blindingly simple in hindsight is why I always feel like an impostor in the low level world :)
- rurban 9y agoAnd the overflow check is now finally cheap in portable C. Before you had to use inline assembly for this trivial ex: add %rax, %rbx jo +4 Now you have the new gcc and clang overflow intrinsics (gcc-5, clang-3.4), which made it cheap and easy to use proper and precise int arithmetic, promoting int to bigint's only on overflow.