Weird Python Integers
kate.io
Weird Python Integers
1–10 of 150 posts
Re: Weird Python Integers
#2Re: Weird Python Integers
#3Re: Weird Python Integers
#4Re: Weird Python Integers
#5> The current implementation keeps an array of integer objects for all integers between -5 and 256, when you create an int in that range you actually just get back a reference to the existing object. So it should be possible to change the value of 1. I suspect the behaviour of Python in this case is undefined. :-)
does anyone have any idea how they chose that range? it's a 262-wide block starting at -5, which seems incredibly arbitrary.
Re: Weird Python Integers
#6 MOST-NEGATIVE-FIXNUM, value: -1152921504606846976
MOST-POSITIVE-FIXNUM, value: 1152921504606846975
Fixnums are typically stored inline in data structures (like lists, arrays and CLOS objects). Bignums will be stored as a pointer to an heap-allocated large number. Data has tags and thus in a 64bit Lisp the fixnums will be slightly smaller than 64bit. Bignums can be 'arbitrary' larger and there is automatic switching between fixnums and bignums for numeric operations.Re: Weird Python Integers
#7the python documentation [1] says the following: > The current implementation keeps an array of integer objects for all integers between -5 and 256, when you create an int in that range you actually just get back a reference to the existing object. So it should be possible to change the value of 1. I suspect the behaviour of Python in this case is undefined. :-) does anyone have any idea how they chose that range? it…
Re: Weird Python Integers
#8Re: Weird Python Integers
#9Unfortunately this blog post seems to miss a great opportunity to show you how you should compare integers for equality -- using the equality operator `==` and not the identity comparison `is`.
EDIT: odd, this post attracted a lot of downvotes. Please help me learn how this post could be improved.
Re: Weird Python Integers
#10the python documentation [1] says the following: > The current implementation keeps an array of integer objects for all integers between -5 and 256, when you create an int in that range you actually just get back a reference to the existing object. So it should be possible to change the value of 1. I suspect the behaviour of Python in this case is undefined. :-) does anyone have any idea how they chose that range? it…
You could probably find out from the code's log. I'd guess the small positive integers are common due to e.g. iteration or len() of small collections and the like, and the very small negatives are due to things like error values.