/****************************************************************************** * Various trigonometric approximations to Pi. * * Copyright © 2017 Richard Lesh. All rights reserved. *****************************************************************************/ import org.pureprogrammer.Utils; public class ComputePi1 { public static void main(String[] args) { final double PI1 = Math.atan(1.0) * 4.0; final double PI2 = Math.atan2(0.0, -1.0); final double PI3 = Math.acos(-1.0); final double PI4 = 2.0 * Math.acos(0.0); System.out.println(Utils.format("pi1: {0:.15f}", PI1)); System.out.println(Utils.format("abs(pi1 - π): {0:.10e}", Math.abs(PI1 - Math.PI))); System.out.println(Utils.format("pi2: {0:.15f}", PI2)); System.out.println(Utils.format("abs(pi2 - π): {0:.10e}", Math.abs(PI2 - Math.PI))); System.out.println(Utils.format("pi3: {0:.15f}", PI3)); System.out.println(Utils.format("abs(pi3 - π): {0:.10e}", Math.abs(PI3 - Math.PI))); System.out.println(Utils.format("pi4: {0:.15f}", PI4)); System.out.println(Utils.format("abs(pi4 - π): {0:.10e}", Math.abs(PI4 - Math.PI))); } }