This site requires JavaScript, please enable it in your browser!
Greenfoot back

Comments for BigDecimal Demo (pi calculator)

Return to BigDecimal Demo (pi calculator)

A new version of this scenario was uploaded on Wed Jul 04 13:53:29 UTC 2012 Tried to fix the size.
tylerstylers

2012/7/4

the source is missing
mjrb4mjrb4

2012/7/4

I'm not sure how you're calculating it, but it's doing so incredibly slowly!
A new version of this scenario was uploaded on Wed Jul 04 15:22:13 UTC 2012 Source.
SPowerSPower

2012/7/4

Probably doing this: pi/4= 1 - 1/3 + 1/5 - 1/7 + 1/9 ....
A new version of this scenario was uploaded on Wed Jul 04 15:23:29 UTC 2012
ZamohtZamoht

2012/7/4

@tylers source is there now. @mjrb4 i added the calculation to the act method, because I was worried about crashing if I used a while or for command. @SPower you're right.
SPowerSPower

2012/7/4

That's one of the slower versions of calculating pi. You better use this: pi/4 = 4 * arctan(1/5) - arctan(1/239)
ZamohtZamoht

2012/7/4

This is a BigDecimal demo, and I kinda like the way it calculates slowly. I know that this page is in danish, but if you really wont the value of pi check the bottom of this pdf: http://www.matematiksider.dk/pi/tallet_pi.pdf
ZamohtZamoht

2012/7/4

*want
A new version of this scenario was uploaded on Wed Jul 04 17:06:26 UTC 2012 Made the calculation a little faster. I'm abit slow, but I found out that the size of the BigDecimal scale, made the execute run slower if it was too high. (I changed the scale from 10000 - I thought it would be more precise- to 120). The program is still calculating slowly.
@SPower the way you calculate the arctan function is this arc(x) = x - x^3/3 + x^5/5 - x^7/7 Its just that pi/4 = arctan(1) or 1-1/3+1/5-1/7. So i think Zamoht's method is faster. @Zamoht, I am impressed by your use of BigDecimals. I tried doing so but I had trouble with it. I will use some your code in my series formula scenario (I will give you credit and like your scenario).
Oops, for some reason I am having trouble liking your scenario. :< anyway, I'll try again: you deserve it.
Also, I think the only reason it takes so long to calculate pi is because you are only making one calculation per act cycle. I tried it out using a for loop to calculate 100 times per act frame and the laptop I'm using handled it like pi (pun intended).
ZamohtZamoht

2012/7/4

@MatheMagician thank you so much. Feel free to use the code, hope you can get use of it. The idea about making loops is good. Thanks again!