top | item 6800168

(no title)

greenlakejake | 12 years ago

Off topic(since it's not about C/Java), but Python has a long integer type which won't over/underflow unless you run out of memory.

% python

Python 2.7.5 (default, Aug 25 2013, 00:04:04)

[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> i = long(9999999999999999999999999999999)

>>> i

9999999999999999999999999999999L

>>>

discuss

order

masklinn|12 years ago

> Python has a long integer type which won't over/underflow unless you run out of memory.

IIRC, so do Erlang, Ruby or Haskell (when using `Integer`), FWIW. And Java has BigInteger (though that one's a pain to use).

But there's a cost to their existence (they need to check for overflow at every operation), and a cost to going above machine word size. Also, now you've got "integers" which can take arbitrary amounts of memory and integer operations in O(n)

Still, definitely a plus on the correctness side.

There's also the option of type-encoded value ranges as in Pascal or Ada.