Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handling REALLY big numbers
#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


Messages In This Thread
Handling REALLY big numbers - by Hazzy - 2010-04-20, 10:29 PM
Handling REALLY big numbers - by Cyadd - 2010-04-20, 10:51 PM
Handling REALLY big numbers - by Hazzy - 2010-04-20, 10:52 PM
Handling REALLY big numbers - by Cyadd - 2010-04-20, 10:57 PM
Handling REALLY big numbers - by Russt - 2010-04-21, 01:45 AM
Handling REALLY big numbers - by Stereo - 2010-04-21, 01:53 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)