Clicky

Jump to content
Ethan Schuman

With regards to PI...

Recommended Posts

In the comments bar, Eriksson asked how many known digits of PI were known.

According to this article, PI has been calculated out to five trillion decimal places.


/>http://www.physorg.com/news200209829.html

Xoza Tyron then replied with:

llGetLength((string)PI)

Naturally, I laughed when I saw that. That statement is quite ridiculous, but I wanted to see just how ridiculous it really was. So I opened up a new script and fired up my handy dandy Windows Calculator, then got to work.

First, we must find the maximum possible length of a string. Strings in Second Life are limited only by the amount of memory available to the script. LSL scripts have 16kb of memory available to them. Mono scripts can use up to 64kb. For the sake of this exercise, I used Mono scripts that consisted of nothing more than a string definition inside state entry. Variables defined inside states use less memory than global variables. The string storage script looks like this:

default

{

state_entry()

{

string s = "";

}

}

With this in hand, I set out to find just how many characters I could put into a string before causing a stack heap collision (running out of memory). After a little bit of experimenting, I discovered that such a string could hold exactly 31,475 characters. I experimented with this manually, not with llGetFreeMemory() (that stores only 31,069 characters, as memory is required to trigger the report).

So! Let's do some math.

5,000,000,000,002 (don't forget "3.")

/ 31,475

=================

158856235.10729150119142176330421

So, it would take 158,856,236 strings to store the full calculated value of PI. As these strings (except for the last one) require the entire memory allocation of the script, it would take that many scripts to hold PI.

Now that we know how many scripts it would take to store PI, we can calculate the amount of memory it would take to hold PI in Second Life. Mono scripts can use 64kb of memory. Let's break that down.

158,856,236

* 64

=================

10,166,799,104 kb (* 1024 = 10,410,802,282,496 bytes, if you're curious)

/ 1,024

=================

9,928,514.75 Mb

/ 1,024

=================

9,695.815185546875 Gb

/ 1,024

=================

9.4685695171356201171875 TB

Just to hold PI to the precision calculated by Kondo and Yee in scripts, it would take roughly 9.47 Terabytes.

Now, according to http://gridsurvey.com/ on August 23, 2010, there are 31,528 sims total on the Second Life main grid. If we were to spread the storage of PI equally in each sim on the grid (including homesteads and voids), this is how it would break down:

String/Script Distribution

158,856,236

/ 31,528

=================

5,038.5763765541740674955595026643 (rest was truncated by Calculator) String/Scripts per sim.

For the sake of preventing madness, we'll round that up to 5,038.5764. That's a lot of scripts. Let's take a look at just how much memory that would eat up.

5,038.5764

* 64

=================

322,468.8896 kb

/ 1024

=================

314.911025 Mb

That's right. Just to store the value of PI to its most recent level of precision would require a little less than 315 Mbs of memory on EVERY sim. So the next time somebody says something like, "llGetLength((string)PI)" you too can laugh to yourself.

This message has been a public service announcement brought to you by Ethan "I'd rather spend twenty minutes figuring out memory usage and doing pointless math than actually work on something productive" Schuman.

Link to comment
Share on other sites

You just did a whole bunch of elementary algebra to find an utterly inconsequential, arbitrary value describing nothing of value. No one could ever possibly use that conclusion for anything serious, ever. Thank you Ethan.

Edited by Aelus Janus
Link to comment
Share on other sites

LSL does not store all the current approximated digits of pi, nor can it calculate it on its own due to memory limitations, therefore LSL cannot count pi's digits. Therefore Xoza's answer is invalid, although I'm sure he was just making a funny.

As a side note:

The elegant way to express pi: C/(2*r) = π

Despite Xoza's response to Eriksson's inquiry being invalid, Xoza's method of expressing pi is inherently better than a "trillion approximation (as Ethan describes)." Calling PI in LSL probably initiates an infinite series summation that approaches the above formula, which will terminate at an unspecified, high amount of digits. This high amount of digits is a truncated version of any "trillion" pi decimal approximation which in all human purposes is the same-- and takes far less time.

Link to comment
Share on other sites

You just did a whole bunch of elementary algebra to find an utterly inconsequential, arbitrary value describing nothing of value. No one could ever possibly use that conclusion for anything serious, ever. Thank you Ethan.

It took me twice as long to type that post than it did to do the calculations (just basic multiplication and division =p), with the significant majority of the time being used to determine the exact possible length of the string. As for my little "utterly inconsequential, arbitrary value describing nothing of value. No one could ever possibly use that conclusion for anything serious, ever," the maximum possible length of a string in SL is something that could quite likely be relevant to an advanced scripter, especially if working on a project that involves measured memory usage. The exact memory usage of llSay(0, (string)llGetFreeMemory) is even more significant, as a scripter can then determine how much memory is REALLY available at a given point.

So there. =p

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×

Important Information

By using this site, you agree to our Privacy Policy, and Terms of Use.