Trebor37
Posts: 42
Joined: Thu Nov 19, 2015 1:39 am

How large a number can a RP2 handle?

Thu Jan 28, 2016 1:56 am

I am working with a group if 8th graders on RP2's and Python 3. One of them asked how the computer could work with infinity. I said that it couldn't that there was a limit to how large a number it could represent. At home I was looking at a Dummies book on Python that said that a 64 bit computer could only represent integers between + of - 2**64 and real numbers between + or - 1.797. . . * 10 ** 308. However, i was able to compute 2**1000 and got a 246 digit number. It didn't even complain when I had it print(int(2**1000)) which should have been an integer not a real number. What gives? What do I tell the kids?

rzusman
Posts: 333
Joined: Fri Jan 01, 2016 10:27 pm

Re: How large a number can a RP2 handle?

Thu Jan 28, 2016 2:29 am

A 64 bit computer can only work with numbers up to 2^64 in a single operation.
This means that the ALU in the processor can do operations on integers of this size without relying on external libraries.
However, with the addition of math libraries, even an 8-bit processor can do math of arbitrary precision.

W. H. Heydt
Posts: 9211
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: How large a number can a RP2 handle?

Thu Jan 28, 2016 2:35 am

You can represent a number as an array of digits and do arithmetic on the array. The number of digits that can be represeneted will be limited by storage space, though it's best to limit oneself to real memory. I once wrote a FORTRAN program that did this to calculate e (the base for natural logarithms that starts 2.718...) to 5000 decimal places. This was done on a 60-bit processor with far less memory than a Pi. It took a CDC 6400 11 CP minutes. (Which isn't as bad as the ALC program I wrote to generate all 3x3x3 solutions to the Soma Cube, which took an IBM S/360-50 4.5 hours.)

User avatar
jackokring
Posts: 815
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: How large a number can a RP2 handle?

Thu Jan 28, 2016 2:37 am

Mathematica accepts 2^1000 for the same result. With virtual memory the number can be very, very big, but calculation will slow substantially, just as accounting carry between digits can consume more ink. This number maximum though is far short of infinity.
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

Trebor37
Posts: 42
Joined: Thu Nov 19, 2015 1:39 am

Re: How large a number can a RP2 handle?

Thu Jan 28, 2016 3:19 am

Thanks for the info. Incidentally, I did 2**3000 and the answer was displayed in less than a blink of an eye.

Heater
Posts: 10236
Joined: Tue Jul 17, 2012 3:02 pm

Re: How large a number can a RP2 handle?

Thu Jan 28, 2016 6:48 am

Sure a computer can handle infinity. Like this in Javascript:

Code: Select all

> 1 / 0
Infinity
> 
Of course that is not very useful apart from the fact that it alerts you as to failure in your code.

With the magic of big number libraries we can work with numbers as big as can fit in memory. Python just happens to have this built into the language. Integers only mind.

Aside: The world record for calculating the digits of Pi stands at 13 trillion digits. It was done on basically a regular Intel computer!

Return to “General discussion”