Skip to content

Instantly share code, notes, and snippets.

@realeroberto
Created September 15, 2018 22:28
Show Gist options
  • Save realeroberto/43a69bf99c580d26eb7504cdc21d7903 to your computer and use it in GitHub Desktop.
Save realeroberto/43a69bf99c580d26eb7504cdc21d7903 to your computer and use it in GitHub Desktop.
Approximate PI with the aid of Wallis' product
#!/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