Created
March 15, 2019 12:38
-
-
Save sudojunior/ca8deae5450b6f497b5182f50ddc3c44 to your computer and use it in GitHub Desktop.
Versions of calculating PI (where [x] ≒ [PI])
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
console.clear(); | |
console.log('[Start]'); | |
sqrt = Math.sqrt; | |
a = n = 1; | |
g = 1 / sqrt(2); z = 1 / 4; half = 1 / 2; | |
for(var i = 0; i < 30; i++) { | |
x = [(a + g) * half, sqrt(a * g)]; | |
val = x[0] - a; | |
z -= val * val * n; | |
n += n; | |
a = x[0]; g = x[1]; | |
} | |
console.log(a * a / z); | |
console.log('[End]'); | |
// Failure - 15 point decimal rounding |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment