pi with 1000 digits
Feb. 9, 2012
9:28 p.m.
Hi, Just for fun, to see how Smalltalk handles precision, 1000 decimals of pi in 10 lines of code. (arctan is redefined not to use floats, change 1000 to 100 for quick result, any variations welvome) in a workspace: | arctan pi | "arctan(x) using Taylor formula" arctan := [ :x :n | | r s | "x must be a fraction- n is the length of the serie" r := (0 to: n) inject: 0 into: [ :sum :k | sum + ((-1 raisedTo: k) * ( x raisedTo: ((2*k) + 1)) / ((2*k) +1)) ] . r ]. "pi using Machin formula" pi := (16* (arctan value: (1/5) value: 1000)) - (4*(arctan value: (1/239) value: 1000) ) asScaledDecimal: 1000. pi inspect. Cheers Alain
5286
Age (days ago)
5286
Last active (days ago)
0 comments
1 participants
participants (1)
-
Alain Rastoul