I am trying to use an ALU and Leibniz Series to approximate pi using only integer operations ie multiplication and shifting. Does anyone know how I could program this in C?
Asked
Active
Viewed 332 times
0
-
Depending on what the purpose of this exercise is, use of a [*spigot algorithm*](https://en.wikipedia.org/wiki/Spigot_algorithm) may be a good choice. As far as I know, the algorithms are not based on the Leibniz formula for π, however. – njuffa Mar 07 '20 at 20:57
1 Answers
0
sum = 0;
for (int i = 1; i <= 10; i++) {
sum = sum + (-1) * (1 / (2.0 * i + 1));
}
Printf("Pi=%f",4 * (sum + 1));

Norbert
- 2,741
- 8
- 56
- 111

Siva Koteswara Rao
- 129
- 1
- 6
-
1
-
With the promotion to `double`, I don't think that qualifies as "using only integer operations". – John McFarlane Feb 28 '20 at 18:24