Last active
December 4, 2018 13:24
-
-
Save charlesBochet/4486419299f823bd900cb72dfc6d508e to your computer and use it in GitHub Desktop.
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
function computePi() { | |
var bigOne = new Big(1) | |
document.getElementById('pi').innerHTML = | |
((atan(bigOne.div(5)).times(4)).minus(atan(bigOne.div(239)))).times(4) | |
.toPrecision(100) | |
} | |
function atan(x) { | |
var preciseX = new Big(x); | |
var result = preciseX; | |
var xSquared = preciseX.times(preciseX); | |
var term = preciseX; | |
var divisor = new Big(1); | |
while (term != 0) { | |
divisor = divisor.plus(2); | |
term = term.times(xSquared); | |
result = result.minus(term.div(divisor)); | |
divisor = divisor.plus(2); | |
term = term.times(xSquared); | |
result = result.plus(term.div(divisor)); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment