[Edu-sig] Smoother long ints in 2.2a4
Tim Peters
tim.one@home.com
Sat, 29 Sep 2001 22:02:31 -0400
[Kirby Urner]
> New in 2.2a4 -- conversion to long integer happens automatically
> when needed:
>
> >>> 2**34
> 17179869184L
> >>> a =1983409182340981239481
> >>> a
> 1983409182340981239481L
>
> I like it!
Me too <wink>.
Note that this is a partial implementation of PEP 237 (Unifying Long
Integers and Integers), and indeed is as much as we dared implement without
tickling serious compatibility issues:
http://python.sourceforge.net/peps/pep-0237.html
There are some other new niceties hiding in 2.2a4, like
>>> import math
>>> math.log10(10 ** 10000)
10000.0
>>>
In earlier versions, you got an infinity, NaN, or simply nonsense, from
trying to find the log of a long too big to convert to a C double. That
bothered me for about 10 years -- so one guess as to who fixed it <wink>.
About that "compatibility" issue: There's one context where ints don't
auto-convert to longs as needed, and that's left shifts:
>>> 1L << 100
1267650600228229401496703205376L
>>> 1 << 100
0
>>>
I don't know what we can do about that, because we *know* there's code out
there that depends on (short) int left shifts acting as if in a fixed-width
window, losing the bits shifted "off the end". The other cases of
auto-conversion raised OverflowError before, and it's hard to conceive of
working code that will miss that (all examples we found caught the
OverflowError and then redid the computation from scratch after explicitly
converting to long); but left-shift behavior both was and would remain
silent, but with different results.