public class Pi2 extends java.lang.Object implements ITask<java.math.BigDecimal>
Modifier and Type | Field and Description |
---|---|
private int |
digits
digits of precision after the decimal point
|
static ITaskFactory<java.math.BigDecimal> |
FACTORY
An ITaskFactory for this task
|
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 and Description |
---|
Pi2(int digits)
Construct a task to calculate pi to the specified
precision.
|
Modifier and Type | Method and Description |
---|---|
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.
|
ITaskResultFormatter<java.math.BigDecimal> |
getFormatter()
Return a a formatter that makes a string of the form:
"Pi = [result] ([digits] places)"
Notice how the "digits" value is not part of the result, but that the
formatter can use it anyway because the formatter is closing over
the whole task.
|
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.
|
private static final long serialVersionUID
private transient ILocalTaskViewAdapter taskView
private static final java.math.BigDecimal FOUR
private static final int roundingMode
private final int digits
public static final ITaskFactory<java.math.BigDecimal> FACTORY
public Pi2(int digits)
digits
- the number of digits to calculate PI topublic java.math.BigDecimal execute()
private java.math.BigDecimal computePi(int digits)
digits
- the number of digits of precision desiredprivate java.math.BigDecimal arctan(int inverseX, int scale)
inverseX
- integer whose inverse will be used to calculate the arctanscale
- number of digits of precision desiredprivate void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, java.lang.ClassNotFoundException
stream
- The object stream with the serialized datajava.io.IOException
- if the input stream cannot be read correctlyjava.lang.ClassNotFoundException
- if the class file associated with the input stream cannot be located.public void setTaskViewAdapter(ILocalTaskViewAdapter viewAdapter)
setTaskViewAdapter
in interface ITask<java.math.BigDecimal>
viewAdapter
- an adapter to the view.public ITaskResultFormatter<java.math.BigDecimal> getFormatter()
getFormatter
in interface ITask<java.math.BigDecimal>