Package org.apfloat.samples
Class Pi
- java.lang.Object
-
- org.apfloat.samples.Pi
-
- Direct Known Subclasses:
PiParallel
public class Pi extends java.lang.ObjectCalculates pi using four different algorithms.- Version:
- 1.14.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classPi.AbstractBinarySplittingSeriesAbstract base class for the binary splitting series.protected static classPi.BinarySplittingPiCalculatorClass for implementing the binary splitting algorithm.static classPi.BinarySplittingProgressIndicatorIndicates progress of the pi calculation using the binary splitting algorithm.protected static interfacePi.BinarySplittingSeriesTerms for the binary splitting series.static classPi.BorweinPiCalculatorCalculates pi using the Borweins' quartic algorithm.protected static classPi.ChudnovskyBinarySplittingSeriesChudnovskys' algorithm terms for the binary splitting series.static classPi.ChudnovskyPiCalculatorBasic class for calculating pi using the Chudnovskys' binary splitting algorithm.static classPi.GaussLegendrePiCalculatorCalculates pi using the Gauss-Legendre algorithm.protected static classPi.RamanujanBinarySplittingSeriesRamanujan's algorithm terms for the binary splitting series.static classPi.RamanujanPiCalculatorBasic class for calculating pi using the Ramanujan binary splitting algorithm.
-
Constructor Summary
Constructors Constructor Description Pi()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static voiddump()static java.io.PrintWritergetErr()Get the output stream for status messages printout.protected static intgetInt(java.lang.String arg, java.lang.String name, int minValue, int maxValue)Parse an integer from an argument.protected static longgetLong(java.lang.String arg, java.lang.String name, long minValue, long maxValue)Parse a long from an argument.static java.io.PrintWritergetOut()Get the output stream for the result printout.protected static longgetPrecision(java.lang.String arg)Parse the precision from an argument.protected static intgetRadix(java.lang.String arg)Parse the radix from an argument.static voidmain(java.lang.String[] args)Command-line entry point.static voidrun(long precision, int radix, Operation<Apfloat> operation)Execute an operation and display some additional information.static voidsetErr(java.io.PrintWriter err)Set the output stream for status messages printout.static voidsetOut(java.io.PrintWriter out)Set the output stream for the result printout.
-
-
-
Method Detail
-
getLong
protected static long getLong(java.lang.String arg, java.lang.String name, long minValue, long maxValue)Parse a long from an argument.- Parameters:
arg- The string to be parsed.name- Description of the argument.minValue- Minimum allowed value.maxValue- Maximum allowed value.- Returns:
- Valid
long.
-
getInt
protected static int getInt(java.lang.String arg, java.lang.String name, int minValue, int maxValue)Parse an integer from an argument.- Parameters:
arg- The string to be parsed.name- Description of the argument.minValue- Minimum allowed value.maxValue- Maximum allowed value.- Returns:
- Valid integer.
-
getPrecision
protected static long getPrecision(java.lang.String arg)
Parse the precision from an argument.- Parameters:
arg- The string to be parsed.- Returns:
- Valid precision.
-
getRadix
protected static int getRadix(java.lang.String arg)
Parse the radix from an argument.- Parameters:
arg- The string to be parsed.- Returns:
- Valid radix.
-
dump
private static void dump()
-
run
public static void run(long precision, int radix, Operation<Apfloat> operation) throws java.io.IOException, ApfloatRuntimeExceptionExecute an operation and display some additional information. The return value of the operation is written toout.- Parameters:
precision- The precision to be used.radix- The radix to be used.operation- The operation to execute.- Throws:
java.io.IOException- In case writing the output fails.ApfloatRuntimeException
-
setOut
public static void setOut(java.io.PrintWriter out)
Set the output stream for the result printout.- Parameters:
out- The output stream.
-
getOut
public static java.io.PrintWriter getOut()
Get the output stream for the result printout.- Returns:
- The output stream.
-
setErr
public static void setErr(java.io.PrintWriter err)
Set the output stream for status messages printout.- Parameters:
err- The output stream.
-
getErr
public static java.io.PrintWriter getErr()
Get the output stream for status messages printout.- Returns:
- The output stream.
-
main
public static void main(java.lang.String[] args) throws java.io.IOException, ApfloatRuntimeExceptionCommand-line entry point.- Parameters:
args- Command-line parameters.- Throws:
java.io.IOException- In case writing the output fails.ApfloatRuntimeException
-
-