Skip to content

Commit

Permalink
PowerShell implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
owainkenwayucl committed Nov 29, 2018
1 parent c15fcf5 commit fa1f241
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions powershell_pi_dir/pi.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# PowerShell Pi example.
# Tested on PowerShell Core 6.1.0 on Ubuntu.

$n = 10000000

if ($args.length -gt 0) {
$n = $args[0]
}

Write-Host "Calculating PI using:"
Write-Host " " $n "slices"
Write-Host " 1 process"

$timer = New-Object System.Diagnostics.Stopwatch
$timer.Start()

$s = 0.0
$step = 1.0/$n

for ($i=1; $i -le $n; $i++) {
$x = ($i - 0.5) * $step
$s = $s + (4.0/(1.0+($x*$x)))
}

$p = $s * $step

$timer.Stop()
$elapsed = $timer.ElapsedMilliseconds/1000
Write-Host "Obtained value of PI:" $p
Write-Host "Time taken:" $elapsed "seconds"

0 comments on commit fa1f241

Please sign in to comment.