Class Pi

  • Direct Known Subclasses:
    PiParallel

    public class Pi
    extends Object
    Calculates pi using four different algorithms.
    Version:
    1.8.2
    Author:
    Mikko Tommila
    • Field Detail

      • out

        protected static PrintWriter out
        Output stream for the result printout.
      • err

        protected static PrintWriter err
        Output stream for status messages printout.
    • Method Detail

      • getLong

        protected static long getLong​(String arg,
                                      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​(String arg,
                                    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​(String arg)
        Parse the precision from an argument.
        Parameters:
        arg - The string to be parsed.
        Returns:
        Valid precision.
      • getRadix

        protected static int getRadix​(String arg)
        Parse the radix from an argument.
        Parameters:
        arg - The string to be parsed.
        Returns:
        Valid radix.
      • run

        public static void run​(long precision,
                               int radix,
                               Operation<Apfloat> operation)
                        throws IOException,
                               ApfloatRuntimeException
        Execute an operation and display some additional information. The return value of the operation is written to out.
        Parameters:
        precision - The precision to be used.
        radix - The radix to be used.
        operation - The operation to execute.
        Throws:
        IOException - In case writing the output fails.
        ApfloatRuntimeException
      • setOut

        public static void setOut​(PrintWriter out)
        Set the output stream for the result printout.
        Parameters:
        out - The output stream.
      • getOut

        public static PrintWriter getOut()
        Get the output stream for the result printout.
        Returns:
        The output stream.
      • setErr

        public static void setErr​(PrintWriter err)
        Set the output stream for status messages printout.
        Parameters:
        err - The output stream.
      • getErr

        public static PrintWriter getErr()
        Get the output stream for status messages printout.
        Returns:
        The output stream.
      • setAlive

        public static void setAlive​(boolean isAlive)
        Set whether the program should stop executing.
        Parameters:
        isAlive - true to keep running the program, false to stop.
      • checkAlive

        protected static void checkAlive()
        Check whether the program should stop executing.
        Throws:
        ThreadDeath - in case setAlive(boolean) has been set to false.