Ethan Schuman Posted August 25, 2010 Share Posted August 25, 2010 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.htmlXoza 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.10729150119142176330421So, 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 TBJust 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 Distribution158,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 MbThat'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. Quote Link to comment Share on other sites More sharing options...
Sylth Stormcrow Posted August 25, 2010 Share Posted August 25, 2010 If you applied all this thinking to something productive, like scripting armour to actually protect people a little, or something else to add to combat in SL, you'd probably make alot of $L Quote Link to comment Share on other sites More sharing options...
Xoza Posted August 25, 2010 Share Posted August 25, 2010 You know.. I use that every so often as a "Its really freaking long" explanation, but I've never actually tossed it together. Thanks Ethan Quote Link to comment Share on other sites More sharing options...
Aelus Posted August 25, 2010 Share Posted August 25, 2010 (edited) 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 August 25, 2010 by Aelus Janus Quote Link to comment Share on other sites More sharing options...
Cygna Posted August 25, 2010 Share Posted August 25, 2010 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. Quote Link to comment Share on other sites More sharing options...
Trinity Heckroth Posted August 25, 2010 Share Posted August 25, 2010 It's super effective. Quote Link to comment Share on other sites More sharing options...
Aryte Posted August 25, 2010 Share Posted August 25, 2010 No way LOL Quote Link to comment Share on other sites More sharing options...
Sherdan Kinomis Posted August 25, 2010 Share Posted August 25, 2010 It's super effective.I am so doing that my next math test. Quote Link to comment Share on other sites More sharing options...
Eriksson Foxtrot Posted August 25, 2010 Share Posted August 25, 2010 Well, let me say. I certainly wasn't expecting a response... but a response this packed? Well-done Ethan.I actually just posted the thing for lulz to see if people would bother replying with an accurate answer, or shove out the ole' "GOOGLE IT." answer.Great read, thank you Ethan! Quote Link to comment Share on other sites More sharing options...
Ethan Schuman Posted August 25, 2010 Author Share Posted August 25, 2010 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 Quote Link to comment Share on other sites More sharing options...
Tiridates Mikadze Posted October 5, 2010 Share Posted October 5, 2010 This argument is so important I'm falling asleep reading it. Quote Link to comment Share on other sites More sharing options...
Fox Cheri Posted November 13, 2010 Share Posted November 13, 2010 If you really want to see just how big Pi is now, then look here and knock your socks off. Trust me. I gaped.../>http://newton.ex.ac.uk/research/qsystems/collabs/pi/pi6.txt Quote Link to comment Share on other sites More sharing options...
Mark Karlfeldt Posted November 13, 2010 Share Posted November 13, 2010 (edited) This reminds me of all the times I would use a script that calculates pi to crash Lil Carducci's sim.We even managed to make it into a bullet which would calculate pi on impact. Edited November 13, 2010 by Mark Karlfeldt Quote Link to comment Share on other sites More sharing options...
Cygna Posted November 13, 2010 Share Posted November 13, 2010 Wolfram Alpha will simulate quite a few digits. :o I stopped at 4571 as it began to be a bit laggy./>http://www.wolframalpha.com Quote Link to comment Share on other sites More sharing options...
Agares Tretiak Posted November 14, 2010 Share Posted November 14, 2010 [media]http://www.youtube.com/watch?v=duVq7cXWcYw&feature=relatedThis adequately displays my complex relationship with "teh numbars". Quote Link to comment Share on other sites More sharing options...
Desereck Creeggan Posted November 15, 2010 Share Posted November 15, 2010 LOL AgaresAlso I tried to calculate PI to the 999,999 digit. I crashed the Wolfram Alpha server./>http://www.wolframalpha.com/input/?i=N[Pi,+999999]&asynchronous=pod&s=47&incTime=trueThis Wolfram|Alpha server is temporarily unavailable. Quote Link to comment Share on other sites More sharing options...
Trinity Heckroth Posted November 15, 2010 Share Posted November 15, 2010 We even managed to make it into a bullet which would calculate pi on impact.And then put it into an infinite ammo minigun? Quote Link to comment Share on other sites More sharing options...