Implementing Borwein Algorithm in Java
Borwein’s algorithm is a calculation contrived by Jonathan and Peter Borwein to compute the estimation of 1/π. They conceived a few different algorithms. The following implementation of Borwein’s algorithm with quartic assembly in Java in fact ascertains Pi, however, converges excessively fast. In principle, a merges quartic ally to 1/π. On every emphasis, the number of correct digits is in this way quadrupled.
Math library of java is used in implementing the Borwein algorithm which is the power and the root function of the library that is Math pow(). The java.lang.Math.pow() is used to calculate a number raised to the power of some other number. This function accepts two parameters and returns the value of the first parameter raised to the second parameter.
In an implementation, from the Math module, two inbuilt functions are used as listed below:
1. pow() function
public static double pow(double a, double b) ;
- a: Base value whose power root is to be returned.
- b: Exponent value to be returned.
Return: This method returns ab.
2. sqrt() function
Math sqrt() The java.lang.Math.sqrt() returns the square root of a value of type double passed to it as argument.
public static double sqrt(double a) ;
Parameter: The value whose square root is to be returned.
Return: This method returns the positive square root value of the argument passed to it.
Value of 1/pi : 0.31830988618379075