maximum value for long?

Bengt Richter bokr at oz.net
Wed Nov 19 01:05:31 EST 2003


On Tue, 18 Nov 2003 21:45:45 -0500, "Terry Reedy" <tjreedy at udel.edu> wrote:

>
>"S.Susnjar" <forth at gmx.de> wrote in message
>news:baab8c40.0311180906.a4ab9f7 at posting.google.com...
>> Hello all,
>
>Hi.
>
>> I have been programming in Python only for a month or so and have
>stumbled
>> over a "problem" that I could not solve through rtfm.
>
>Ref Man 3.2 The standard type hierarchy
>"
>There are two types of integers:
>
>Plain integers
>These represent numbers in the range -2147483648 through 2147483647.
>(The range may be larger on machines with a larger natural word size,
>but not smaller.) When the result of an operation would fall outside
>this range, the exception OverflowError is raised. For the purpose of

Seems out of date re version 2.3.2:

 >>> x = 2**30
 >>> x
 1073741824
 >>> type(x)
 <type 'int'>
 >>> x+x
 2147483648L
 >>> type(x+x)
 <type 'long'>


>shift and mask operations, integers are assumed to have a binary, 2's
>complement notation using 32 or more bits, and hiding no bits from the
>user (i.e., all 4294967296 different bit patterns correspond to
>different values).
>
>Long integers
>These represent numbers in an unlimited range, subject to available
>(virtual) memory only. For the purpose of shift and mask operations, a
>binary representation is assumed, and negative numbers are represented
>in a variant of 2's complement which gives the illusion of an infinite
>string of sign bits extending to the left.
>"
Though <rant>hex of negative numbers is slated for ugliness (IMO) in version 2.4
in the form of '-' prefixing the hex of the absolute value -- making it useless
for the normal bit pattern visualization that one would like when looking at bitwise
operations. Ugh! Barf!</rant>.

>In short, Python ints are C longs, while Python longs are extended or
>arbitrary precision, and hence truly long.  Your confusion over the
>two meanings of 'long' is not unique among people with a C background
>;-).
>

Regards,
Bengt Richter




More information about the Python-list mailing list