Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handling REALLY big numbers
#1
Googled around a bit after reading that other Python Thread. Found this.
Copied it, saved it, ran it. Surprised at how fast it ran, since I wrote a program to do the same thing, in the same manor, a while ago on my TI83 Calculator. 2009 Computer runs faster than a '99 Handheld Calculator. Shocking, amirite?

Anyway, I want to push it. To play with it. So I check out Wikipedia's page on Prime Numbers and find some fairly large ones (over 2 million)

Enter the numbers into the program and get an error. "argument is not of int type" I assume that's the script not being able to store memory for numbers as large as the ones I was trying.

How can I get around this? What would I need to do to make the program, or any program, for that matter, handle and save incredibly large numbers, without dropping digits?

If my assumption is wrong, what's actually happening?

Edit:
When I say "REALLY big", I'm thinking around the order of 10^1000.
Reply
#2
just change the data types to something larger that can handle those large numbers. Octaword or double quadword for fun.
Reply
#3
I thought the largest datatype was long unsigned int. Brbtesting double quadword.

Edit:
Replaced all the occurrences of int with quadword and got errors. Do I need to include(?) something?
Reply
#4
I'm not exactly sure on how large of a number you can get in Python.
Reply
#5
Hm, I thought all numbers in Python were doubles, like in Lua and Javascript.

Edit: Ah nevermind, didn't look at the script. Your large numbers fail "if not isinstance(n, int)"
There's a good reason it only takes ints. Primality checks can't afford to lose precision.

There are ways to store arbitrarily large exact numbers (i.e. bignums). One approach would be to have an array of ints, each one representing 4 digits of the number or so. Then you define operations to add, subtract, multiply, and divide those arrays, just as you would perform those operations by hand. Long division of bignums would be painfully inefficient for primality checking, though.
Reply
#6
Probably want something like NTL, I don't know what the Python equivalent is though. Gives you support for arbitrary length integers along with the basic operations on them.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)