provided.client.model.task
Class Pi2

java.lang.Object
  extended by provided.client.model.task.Pi2
All Implemented Interfaces:
java.io.Serializable, ITask<java.math.BigDecimal>

public class Pi2
extends java.lang.Object
implements ITask<java.math.BigDecimal>, java.io.Serializable

Task to compute PI to a given number of digits

Author:
swong
See Also:
Serialized Form

Field Summary
private  int digits
          digits of precision after the decimal point
private static java.math.BigDecimal FOUR
          constants used in pi computation
private static int roundingMode
          rounding mode to use during pi computation
private static long serialVersionUID
          SerialversionUID for well-defined serialization.
private  ILocalTaskViewAdapter taskView
          Adapter to the local view.
 
Constructor Summary
Pi2(int digits)
          Construct a task to calculate pi to the specified precision.
 
Method Summary
private  java.math.BigDecimal arctan(int inverseX, int scale)
          Compute the value, in radians, of the arctangent of the inverse of the supplied integer to the specified number of digits after the decimal point.
private  java.math.BigDecimal computePi(int digits)
          Compute the value of pi to the specified number of digits after the decimal point.
 java.math.BigDecimal execute()
          Calculate pi.
private  void readObject(java.io.ObjectInputStream stream)
          Reinitializes transient fields upon deserialization.
 void setTaskViewAdapter(ILocalTaskViewAdapter viewAdapter)
          Sets the task view adapter to a new value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
SerialversionUID for well-defined serialization.

See Also:
Constant Field Values

taskView

private transient ILocalTaskViewAdapter taskView
Adapter to the local view. Marked "transient" so that it is not serialized and instead is reattached at the destination (the server).


FOUR

private static final java.math.BigDecimal FOUR
constants used in pi computation


roundingMode

private static final int roundingMode
rounding mode to use during pi computation

See Also:
Constant Field Values

digits

private final int digits
digits of precision after the decimal point

Constructor Detail

Pi2

public Pi2(int digits)
Construct a task to calculate pi to the specified precision.

Parameters:
digits - the number of digits to calculate PI to
Method Detail

execute

public java.math.BigDecimal execute()
Calculate pi.

Specified by:
execute in interface ITask<java.math.BigDecimal>
Returns:
The result of executing the task.

computePi

private java.math.BigDecimal computePi(int digits)
Compute the value of pi to the specified number of digits after the decimal point. The value is computed using Machin's formula: pi/4 = 4*arctan(1/5) - arctan(1/239) and a power series expansion of arctan(x) to sufficient precision.


arctan

private java.math.BigDecimal arctan(int inverseX,
                                    int scale)
Compute the value, in radians, of the arctangent of the inverse of the supplied integer to the specified number of digits after the decimal point. The value is computed using the power series expansion for the arc tangent: arctan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 + (x^9)/9 ...


readObject

private void readObject(java.io.ObjectInputStream stream)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Reinitializes transient fields upon deserialization. See the Serializable marker interface docs. taskView is set to a default value for now (ILocalTaskViewAdapter.DEFAULT_ADAPTER).

Parameters:
stream - The object stream with the serialized data
Throws:
java.io.IOException
java.lang.ClassNotFoundException

setTaskViewAdapter

public void setTaskViewAdapter(ILocalTaskViewAdapter viewAdapter)
Sets the task view adapter to a new value. Used by the server to attach the task to its view.

Specified by:
setTaskViewAdapter in interface ITask<java.math.BigDecimal>
Parameters:
viewAdapter - an adapter to the view.