Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Web Worker Calculates Pi JavaScript
function calculatePi() {
var result = 0;
var denominator = 1;
var add = true;
while (true) {
if(add) {
result = result + 4/denominator;
add = false;
} else {
result = result - 4/denominator;
add = true;
}
this.postMessage(result);
denominator = denominator + 2;
}
}
calculatePi();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment