Fixed problem in Pi calculation algorithm

This commit is contained in:
Jonas Bonér 2011-04-23 11:55:54 +02:00
parent 06c134ca91
commit 2770f47f27
6 changed files with 17 additions and 19 deletions

View file

@ -282,7 +282,7 @@ The only thing missing in our ``Worker`` actor is the implementation on the ``ca
private double calculatePiFor(int start, int nrOfElements) {
double acc = 0.0;
for (int i = start * nrOfElements; i <= ((start + 1) * nrOfElements - 1); i++) {
acc += 4 * (1 - (i % 2) * 2) / (2 * i + 1);
acc += 4.0 * (1 - (i % 2) * 2) / (2 * i + 1);
}
return acc;
}
@ -550,7 +550,7 @@ Before we package it up and run it, let's take a look at the full code now, with
private double calculatePiFor(int start, int nrOfElements) {
double acc = 0.0;
for (int i = start * nrOfElements; i <= ((start + 1) * nrOfElements - 1); i++) {
acc += 4 * (1 - (i % 2) * 2) / (2 * i + 1);
acc += 4.0 * (1 - (i % 2) * 2) / (2 * i + 1);
}
return acc;
}