Discuss Scratch

mumu245
Scratcher
1000+ posts

How to calculate Pi?

PhiPhenomenon wrote:

(#11)
There's a pretty cool infinite sum that can be used to calculate pi:

(I swear there's an image, cubeupload's just down)
However, it's pretty slow. You have to sum like the first thousand terms of the terms to get like the first four places of pi.

There's a faster one called the Machin formula, but it requires a little more math:

(There's also an image here)
You can find the arctangent block from the operators section:
([atan v] of ())
Scratch is not precise enough.

* * *

Decimals in Scratch aren't infinitely precise. The computer uses 58 bits, which equates to about 10 digits.
PhiPhenomenon
Scratcher
500+ posts

How to calculate Pi?

mumu245 wrote:

PhiPhenomenon wrote:

(#11)
There's a pretty cool infinite sum that can be used to calculate pi:

(I swear there's an image, cubeupload's just down)
However, it's pretty slow. You have to sum like the first thousand terms of the terms to get like the first four places of pi.

There's a faster one called the Machin formula, but it requires a little more math:

(There's also an image here)
You can find the arctangent block from the operators section:
([atan v] of ())
Scratch is not precise enough.

* * *

Decimals in Scratch aren't infinitely precise. The computer uses 58 bits, which equates to about 10 digits.
If the OP wanted to, they could use the arbitrary-precision arithmetic described in Super Pi Calc by DadOfMrLog. To avoid loss of precision from Scratch decimals, it uses lists to keep track of individual terms. Then it manually sums them together instead of using the addition operator.
Badgamesaremade
Scratcher
9 posts

How to calculate Pi?

WAHHHHHHHHHHHHHHHHHHHHHHH
tim_buck_II
Scratcher
50 posts

How to calculate Pi?

I have a project that does this: https://scratch.mit.edu/projects/982730462/

Edit: I recommend using method 3 (The Gregory-Leibniz series), because while it doesn't converge quite as quickly as method 2 (the Nilakantha series), scratch “lets” it be more accurate once it's finished

Last edited by tim_buck_II (April 12, 2025 22:05:59)

TutoeTurtle
Scratcher
100+ posts

How to calculate Pi?

This is the most accurate way to calculate pi:

1/π = 12 * ∑ ((-1)^k * (6k)! * (13591409 + 545140134k) * (3k)! * (k!)^3) / (640320^(3k+3/2))

Unfortunately, there's no sum operator ( ∑ ) in scratch so… yeah. The Chudnovsky Algorithm doesn't work well on scratch.
N8_D_GR8_1
Scratcher
1000+ posts

How to calculate Pi?

TutoeTurtle wrote:

This is the most accurate way to calculate pi:

1/π = 12 * ∑ ((-1)^k * (6k)! * (13591409 + 545140134k) * (3k)! * (k!)^3) / (640320^(3k+3/2))

Unfortunately, there's no sum operator ( ∑ ) in scratch so… yeah. The Chudnovsky Algorithm doesn't work well on scratch.
I made a program with that algorithm. The problem is I didn't plan for having more than 16 digit precision, so it doesn't get that many digits. It's fast though! https://scratch.mit.edu/projects/1145688427/
TutoeTurtle
Scratcher
100+ posts

How to calculate Pi?

TheUltimateHoodie wrote:

PhiPhenomenon wrote:

TheUltimateHoodie wrote:

but my teacher said to use that

did my teacher lie to me?
The OP wants an approximation of pi that goes on as long as they can. 22/7 comes out to about 3.1428. That's a 0.0403% error from the actual value of pi, so it's fine to use in calculations. However, it's 3rd decimal place is already wrong.
so…my teacher lied…she said 22/7 WAS pi
Yup she either didn't know or was just simplifying so you could remember it better.
somethingelse0_0
Scratcher
65 posts

How to calculate Pi?

TheUltimateHoodie wrote:

Vaibhs11 wrote:

london11gm wrote:

22/7 = pi
That is a terrible estimation of pi compared to what OP's asking for.
but my teacher said to use that

did my teacher lie to me?
its just for easier calculation, as pi is irrational
somethingelse0_0
Scratcher
65 posts

How to calculate Pi?

there are actually a lot of ways to find pi
somethingelse0_0
Scratcher
65 posts

How to calculate Pi?

Shrek_em wrote:

circumference / diameter
It's impossible to do this, because we cannot measure the circumference and diameter of a circle perfectly. It is a good estimation, but not good enough.

Last edited by somethingelse0_0 (May 24, 2025 09:28:43)

-20thaccount-
Scratcher
52 posts

How to calculate Pi?

MrKingofScratch wrote:

here's a funny approach
https://scratch.mit.edu/projects/682780554/

WHY DOES IT SAY Last edited by kaj (Tomorrow 00:00:00)
N8_D_GR8_1
Scratcher
1000+ posts

How to calculate Pi?

-20thaccount- wrote:

MrKingofScratch wrote:

here's a funny approach
https://scratch.mit.edu/projects/682780554/

WHY DOES IT SAY Last edited by kaj (Tomorrow 00:00:00)
It is just a part of his signature. In case you didn't know, kaj is an older user that made a big commotion about hacking scratch to get attention.

last edited by skibidifarm (-100 BC 99:99:99)

Powered by DjangoBB