Jump to content

how accurate are your π calculations?


bikeman564™

Recommended Posts

In high school, 1980'ish, a guy in my programming class calculated pi to the most digits I have ever seen in real life.  I have no idea the number of digits but it was a wall of numbers that completely filled a sheet of green bar paper used with our teletype console.

  • Awesome 1
Link to comment
Share on other sites

4 hours ago, Mr. Silly said:

In high school, 1980'ish, a guy in my programming class calculated pi to the most digits I have ever seen in real life.  I have no idea the number of digits but it was a wall of numbers that completely filled a sheet of green bar paper used with our teletype console.

I was just wondering how you calculate pi. 
Hmm, looks like the reader’s digest version is Archimedes got very close by comparing 96 sided polygons that fit inside and ootside a circle so that gave upper and lower limits on it. Then infinite series came later, and I did not happen upon a similarly understandable explanation of how they work. 

Link to comment
Share on other sites

35 minutes ago, Razors Edge said:

Would it matter? Past 3.14 (and I know to 3.1415!) is about useless in all but a tiny amount of uses. :D

Back in my mechanical design days it was 3.1416.  Have to round the 5 up.

Link to comment
Share on other sites

1 hour ago, Ralphie said:

I was just wondering how you calculate pi. 
Hmm, looks like the reader’s digest version is Archimedes got very close by comparing 96 sided polygons that fit inside and ootside a circle so that gave upper and lower limits on it. Then infinite series came later, and I did not happen upon a similarly understandable explanation of how they work. 

It is something like:

4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 (...)

  • Thank You 1
  • Like 1
Link to comment
Share on other sites

1 hour ago, Kzoo said:

Back in my mechanical design days it was 3.1416.  Have to round the 5 up.

In school, we were told to use 3.1415 (or 6) can't remember. But this way everyone would get the same answer if correct. Despite calculators having a Pi function. When I'm at the store buying tape for my wheels, I use 3 so I can do it in my head  :D 

Link to comment
Share on other sites

My nephew, now the flight attendant, won tickets to an AA Minor League Bowie Baysox game for reciting pi to something like 17 decimal places when he was in elementary school.  The modern minor league stadiums have playgrounds for kids, picnic tables for adults McDonald's-size prices for concessions and cheap tickets.

Taking a few kids to see the nearby, major league Orioles or Nationals is a financial adventure.

  • Like 1
Link to comment
Share on other sites

19 hours ago, Razors Edge said:

3.14. Forget the rest! Jeebus man. 

When you're working on a tool that is machined to ten thousands of an inch you need 4 significant digits.  Jeebus man, everyone knows that.

 

Link to comment
Share on other sites

1 minute ago, Kzoo said:

When you're working on a tool that is machined to ten thousands of an inch you need 4 significant digits.  Jeebus man, everyone knows that.

Darn it! You're a tiny tool? I thought you were a huge tool, but I'm known to be wrong quite often.

Link to comment
Share on other sites

On 3/17/2024 at 11:55 AM, Mr. Silly said:

It is something like:

4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 (...)

Yes but that will take 500,000 iterations to be accurate to 5 decimal places.   https://www.wikihow.com/Calculate-Pi

On 3/17/2024 at 12:44 PM, bikeman564™ said:

not for things I do, my calculator IIRC is 10 digits. In Excel, I use =Pi()

Yeah... I just use the π key on my calculator.  and the Excel PI().   

  • Like 1
Link to comment
Share on other sites

On 3/17/2024 at 11:55 AM, Mr. Silly said:

It is something like:

4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 (...)

I was curious (and bored watching a movie with WoBG) so I used the Gregory-Leibniz series and wrote an Excel macro to calculate π.  

The macro uses 500,000 iterations and the answer is indeed close.   

I've exceeded my useless drivel quota for the day. :party:

image.thumb.png.a2ff70f17cbfc29f37e807978f333d3d.png

 

  • Awesome 3
Link to comment
Share on other sites

I plagiarized a good chunk of this from Stack Overflow if you want to calculate PI to an arbitrary number of digits using C#.:

 

 

using System ;
namespace SillyMath {
   class Program {
      public static string CalculatePi(int digits) {  
         digits++;
 
         uint[] x = new uint[digits*10/3+2];
         uint[] r = new uint[digits*10/3+2];
         uint[] pi = new uint[digits];
 
         for (int j = 0; j < x.Length; j++)
            x[j] = 20;
         
         for (int i = 0; i < digits; i++) {
            uint carry = 0;
            for (int j = 0; j < x.Length; j++) {
               uint num = (uint)(x.Length - j - 1);
               uint dem = num * 2 + 1;
 
               x[j] += carry;
 
               uint q = x[j] / dem;
               r[j] = x[j] % dem;
 
               carry = q * num;
            }
 
            pi[i] = (x[x.Length-1] / 10);
            r[x.Length - 1] = x[x.Length - 1] % 10; ;
         
            for (int j = 0; j < x.Length; j++)
               x[j] = r[j] * 10;
         }
     
         var result = "";
         uint c = 0;
     
         for(int i = pi.Length - 1; i >=0; i--) {
            pi[i] += c;
            c = pi[i] / 10;
         
            result = (pi[i] % 10).ToString() + result;
         }
      return result;
   }
      static void Main(String[] args) {
         int numDigits = 132 ;
         
         string result = CalculatePi(numDigits) ;
         result = result.Insert(1, ".") ;
         Console.WriteLine(result) ;
      }
   }
}

PS C:\Users\MrSilly\Documents\Dev\CPP\CalcPI\CalcPI> dotnet run
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550

image.png.852a3ab36480f960a4a395360718e07c.png

 

  • Awesome 3
Link to comment
Share on other sites

8 hours ago, Bikeguy said:

I was curious (and bored watching a movie with WoBG) so I used the Gregory-Leibniz series and wrote an Excel macro to calculate π.  

The macro uses 500,000 iterations and the answer is indeed close.   

I've exceeded my useless drivel quota for the day. :party:

image.thumb.png.a2ff70f17cbfc29f37e807978f333d3d.png

I started to do this on Excel also :D but w/o the macro. I figured it was going to be a lot

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...