Skip to content

Instantly share code, notes, and snippets.

@nraychaudhuri
Created August 12, 2015 16:50
Show Gist options
  • Save nraychaudhuri/377ca198b491145147b3 to your computer and use it in GitHub Desktop.
Save nraychaudhuri/377ca198b491145147b3 to your computer and use it in GitHub Desktop.
private void busy(FiniteDuration duration) {
pi(duration.toMillis() * 800);
}
private BigDecimal pi(long m) {
int n = 0;
BigDecimal acc = new BigDecimal(0.0);
while(n < m) {
acc = acc.add(gregoryLeibnitz(n));
n += 1;
}
return acc;
}
private BigDecimal gregoryLeibnitz(int n) {
return new BigDecimal(4.0 * (1 - (n % 2) * 2) / (n * 2 + 1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment