Created
September 15, 2018 22:28
-
-
Save realeroberto/43a69bf99c580d26eb7504cdc21d7903 to your computer and use it in GitHub Desktop.
Approximate PI with the aid of Wallis' product
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/tclsh | |
# | |
# approximate PI with the aid of Wallis' product | |
# | |
proc wallis {{n 1000000}} { | |
set value 1.0 | |
set i 1 | |
while {$i < $n} { | |
set i2 [expr {($i*2)**2}] | |
set value [expr {$value * $i2 / ($i2-1)}] | |
incr i | |
} | |
return $value | |
} | |
puts [expr {2 * [wallis]}] | |
# ex: ts=4 sw=4 et filetype=tcl noexpandtab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment