473,587 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

maximum integer length?

Hey everyone,

I am trying to figure out what is the largest integer I can. Lets say
for 400 megabytes of memory at my disposal.

I have tried a few things
c = 2**1000000
d = 2**2000000
print c**d

Obviously I didn't have enough memory for that, but I was able to c**3.
(I think anyways, it is still trying to display the result)

So I am just wondering how long an integer can be with 400 megabytes of
memory.

I guess this is a question of logic?
each integer takes up a byte right? If I have 400 megabytes that would
mean I could have a long integer with up to 419,430,400,000 integers?

Really I am not sure on this one and that is why I am asking. Because it
is just bugging me I am not sure how it works...

I know this probably seems trivial and just a stupid question, but I
find this type of stuff interesting...
Jun 18 '06 #1
4 3575

nate wrote:
So I am just wondering how long an integer can be with 400 megabytes of
memory.

I guess this is a question of logic?
each integer takes up a byte right? If I have 400 megabytes that would
mean I could have a long integer with up to 419,430,400,000 integers?

Python longs are stored using 15 bits out of every 16 bits (2 bytes).
So every 2 bytes will contain approximately 4.5154 decimal digits.
Ignoring memory usage and overhead, the number of digits in the largest
possible long integer that can fit in 400 megabytes is
import math
200 * 1024 * 1024 * 15 * math.log10(2)

946958486.20006 43

Since memory space is required for temporary storage of intermediate
results, you won't actually be able to create a number that large if
you only have 400 megabytes.

casevh

Jun 18 '06 #2
On 2006-06-18, Sybren Stuvel <sy*******@YOUR thirdtower.com. imagination> wrote:
nate enlightened us with:
Obviously I didn't have enough memory for that, but I was able to c**3.
(I think anyways, it is still trying to display the result)

So I am just wondering how long an integer can be with 400 megabytes of
memory.


I guess the best way would be a binary search for the proper value of
the integer. You already have an upper (c**d) and a lower (c**3) bound
for your search.
each integer takes up a byte right?


That depends on the size of the integer, doesn't it?
If I have 400 megabytes that would mean I could have a long integer
with up to 419,430,400,000 integers?


Que? An integer is just a whole number without fraction. What are you
talking about?


He's talking about decimal digits. Each decimal digit takes up
3.322 bits. A byte can hold about 2.4 digits. 400MB should be
able to hold an integer with about 1,010,000,000 decimal
digits.

--
Grant Edwards
gr****@visi.com
Jun 18 '06 #3
nate wrote:
Hey everyone,

I am trying to figure out what is the largest integer I can. Lets say
for 400 megabytes of memory at my disposal.

I have tried a few things
c = 2**1000000
d = 2**2000000
print c**d

Obviously I didn't have enough memory for that, but I was able to c**3.
(I think anyways, it is still trying to display the result)
Don't print, takes too long. Do e=c**3.

So I am just wondering how long an integer can be with 400 megabytes of
memory.

I guess this is a question of logic?
each integer takes up a byte right? If I have 400 megabytes that would
mean I could have a long integer with up to 419,430,400,000 integers?

Really I am not sure on this one and that is why I am asking. Because it
is just bugging me I am not sure how it works...

I know this probably seems trivial and just a stupid question, but I
find this type of stuff interesting...


Using gmpy (and I don't know if it stores large ints different
from Python ints) and only 192M on my laptop, I can get
to billion bit numbers, but not much larger. Switching to
Python ints ran out of memory trying gen 11. It also ran out
of memory trying to calculate gen 10, which gmpy was able
to do successfully, so maybe gmpy is better for such things:

Closed form: Type12MH(k,i)
Find ith, kth Generation Type [1,2] Mersenne Hailstone
using the closed form equation

2**(6*((i-1)*9**(k-1)+(9**(k-1)-1)/2+1)-1)-1

2**5-1 generation: 1
2**29-1 generation: 2
2**245-1 generation: 3
2**2189-1 generation: 4
2**19685-1 generation: 5
2**177149-1 generation: 6
2**1594325-1 generation: 7
2**14348909-1 generation: 8
2**129140165-1 generation: 9
2**1162261469-1 generation:10

Traceback (most recent call last):
File "C:\python24\us er\user_home\gm py ver 1.01\MHtest.py" , line 41,
in -toplevel-
a = Type12MH(k,1)
File "C:\python24\li b\collatz_funct ions.py", line 595, in Type12MH
return TWO**(SIX*a - ONE) - ONE
ValueError: mpz.pow outrageous exponent


i=1
k=11
a = 2**(6*((i-1)*9**(k-1)+(9**(k-1)-1)/2+1)-1)-1


Traceback (most recent call last):
File "<pyshell#3 >", line 1, in -toplevel-
a = 2**(6*((i-1)*9**(k-1)+(9**(k-1)-1)/2+1)-1)-1
MemoryError

Jun 18 '06 #4
On 2006-06-18, Grant Edwards <gr****@visi.co m> wrote:
Que? An integer is just a whole number without fraction. What are you
talking about?


He's talking about decimal digits. Each decimal digit takes up
3.322 bits. A byte can hold about 2.4 digits. 400MB should be
able to hold an integer with about 1,010,000,000 decimal
digits.


Oops. The real answer is 15/16 of that. I didn't realize that
the integer representation only uses 15 of 16 bits.

--
Grant Edwards
gr****@visi.com

Jun 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4721
by: Hal Vaughan | last post by:
Is there a maximum length for Javascript program lines? What about strings? Is there a limit on string length? I found some references that said the maximum string length was 256 characters, but I have a program that created a string of over 25,000 characters (the browser was Konqueror). Are there limits on these lengths? If I require...
3
5005
by: Dave Crypto | last post by:
Hi There, SUMMARY: I need to know what the actual maximum date limit possible on a row of a MYSQL database. MORE DETAILS: For example, does a MYSQL database only allow 4032 bytes of data to be
2
2320
by: Hennie de Nooijer | last post by:
Because of an error in google or underlying site i can reply on my own issue. Therefore i copied the former entered message in this message. -------------------------------------REPY---------------------------------- Hi Maybe i wasn't clear. I want to dynamically check whether what the lowest date and the highest date is in the calendar table....
2
28557
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
11
13412
by: Leroy | last post by:
Hello, I have a question regarding the maximum number of parameters that can be passed to a procedure. In VB 6 the max was 60. What is the max for Dot Net? please and thanks.
3
36891
by: yawnmoth | last post by:
I'm trying to figure out how big integers in PHP can be and am having some difficulty. My first idea was to try something like this: <? for ($bits=0; (1<<($bits+1)) > (1<<$bits); $bits++); echo $bits; ?>
2
1909
by: ArtOfSpeech | last post by:
hi.... Can anyone tell me plz how to set a maximum number of (lines) to a rich text control and show only last linse when number of lines exceeds the maximum number??? i've tried to use richtext.lines array to determine lines length but i can remove from it cause its of system array type and is length fixed which means i cant add or...
2
3375
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function checkInteger(&$value, $checks) { $err = ''; if (!is_numeric($value) || (floatval($value) != intval($value))) { $err .= 'Input must be an integer. ';
7
6993
by: laredotornado | last post by:
Hi, I'm using PHP 5 with MySql 5. I have a MySQL InnoDB table with a column of type INTEGER UNSIGNED. Is there a constant in PHP to insert the maximum value possible into the column? The underlying OS is Red Hat Linux, but I'm not sure about the version. Any help you can provide is appreciated, - Dave
0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.