Last active
October 11, 2020 19:15
-
-
Save mrunkel/451f1094d8ba379834bd51ed1088dd28 to your computer and use it in GitHub Desktop.
How to calculate pi in PHP.
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
<?php | |
$add = true; | |
$pi = 3; | |
for ($x = 2; $x <10000; $x += 2) { | |
$new = 4/($x * ($x + 1) * ($x + 2)); | |
$pi = $add ? | |
$pi + $new : | |
$pi - $new; | |
$add = !$add; | |
} | |
echo $pi . "<br>"; | |
echo 3.14159265359; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outputs: