Report as inappropriate.

Zamoht presents ...

2012/7/4

# BigDecimal Demo (pi calculator)

The title says it all!
(BigDecimal is a way to get more decimals than you do when using double or float)
I think it's a bit confusing, and there might be other uses of the Bigdecimal class, but here is one of them.

3883 views / 390 in the last 7 days

2 votes | 0 in the last 7 days

Your browser does not support the canvas tag.
A new version of this scenario was uploaded on Wed Jul 04 15:23:29 UTC 2012
Zamoht

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.
SPower

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)
Zamoht

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
Zamoht

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).
Zamoht

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!