Project: Compute π
Write a program that computes and prints the value π which can be easily computed with standard math functions using one of the formula:
- atan(1.0)*4.0
- atan2(0.0, -1.0)
- acos(-1.0)
- 2.0*acos(0.0)
Which formula produces an answer closer to the standard math definition of π?
See [[Pi]]
Output
$ javac -Xlint ComputePi1.java
$ java -ea ComputePi1
pi1: 3.141592653589793
abs(pi1 - π): 0.0000000000e+00
pi2: 3.141592653589793
abs(pi2 - π): 0.0000000000e+00
pi3: 3.141592653589793
abs(pi3 - π): 0.0000000000e+00
pi4: 3.141592653589793
abs(pi4 - π): 0.0000000000e+00