Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Understanding integer limit on python3 using Fibonacci series

I need to better understand the max integer number that can be used in python3.
I used the following instructions to get the max integer size.

>> import sys
>> print(sys.maxsize)
9223372036854775807

So, here I got some integer which I thought was the maximum integer value that python3 will process.
Then, I wrote a small code to get numbers in the Fibonacci series. It looks like this.

fib=[0,1]
file=open('fib.txt','a')
file.write(str(fib[0]))
for i in range(1000):
    fib.append(fib[-1]+fib[-2])
    file.write('\n'+ str(fib[-1]))
file.close()

So, I got my series in the list ‘fib’ and got the series in a text file named ‘fib.txt’. Here, I got the first 1001 numbers in the series (including zero).
Now, when I see the last entry in this series, it shows a very big number.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

70330367711422815821835254877183549770181269836358732742604905087154537118196933579742249494562611733487750449241765991088186363265450223647106012053374121273867339111198139373125598767690091902245245323403501

This number is clearly larger than what ‘sys.maxsize’ showed.
And if I wish I can still do simple mathematical operations on the number so it is not like it is just a string. (I tried only addition and subtraction.)
I do not understand what the max integer is that python can process. Please clarify this.

Thank you.

PS: I am new so please explain accordingly.

>Solution :

Integers

In Python, an integer is an int and is unbounded and should not be confused with integer types (int, long etc) in languages like C++.

What python can handle?

Python can handle arbitrarily large integers in computation. Any integer too big to fit in 64 bits (or whatever the underlying hardware limit is) is handled in software. For that reason, Python 3 doesn’t have a sys.maxint constant.

so what does sys.maxsize do?

The value sys.maxsize, on the other hand, reports the platform’s pointer size, and that limits the size of Python’s data structures such as strings and lists.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading