"I have a mind like a steel... uh... thingy." Patrick Logan's weblog.

Search This Blog

Loading...

Wednesday, May 11, 2005

Jython Integers

Moving Python and other dynamic languages to the popular rigid virtual machines should preserve Python behavior while providing access to the host language and platform capabilities.

When I used Jython a couple years ago I guess I did not stress this behavior. And so today I am a bit surprised to see the following in Jython 2.1...

>>> java.lang.Integer.MAX_VALUE
2147483647
>>> n = java.lang.Integer.MAX_VALUE
>>> n
2147483647
>>> n.__class__

>>> n + 1
Traceback (innermost last):
  File "", line 1, in ?
OverflowError: integer addition: 2147483647 + 1
>>>
Comments

It is a correct behavior. Try evaluating "sys.maxint + 1" on CPython 2.1...

If you do "sys.maxint + 1L", (note "L") it works both on CPython 2.1 and Jython 2.1.

End Comments

OK. So the goal becomes getting Jython up to 2.4 or at least the version past CPython 2.1 where both sys.maxint + 1L and sys.maxint + 1 do the (same) right thing.

Thanks

2 comments:

Anonymous said...

It is a correct behavior. Try evaluating "sys.maxint + 1" on CPython 2.1...

Anonymous said...

If you do "sys.maxint + 1L", (note "L") it works both on CPython 2.1 and Jython 2.1.

Blog Archive

About Me

Portland, Oregon, United States
I'm usually writing from my favorite location on the planet, the pacific northwest of the u.s. I write for myself only and unless otherwise specified my posts here should not be taken as representing an official position of my employer. Contact me at my gee mail account, username patrickdlogan.