com.rubecula.jquantity
Class Complex

java.lang.Object
  extended bycom.rubecula.util.Item
      extended bycom.rubecula.jquantity.Complex
All Implemented Interfaces:
Auditable, java.lang.Cloneable, java.lang.Comparable, Divisible, Identifiable, Imaginable, Millable, Mutable, Nameable, Normalizable, Presentable, java.io.Serializable, Trigonometrical

public class Complex
extends Item
implements Imaginable, Divisible, Trigonometrical, Normalizable, Mutable, Nameable, Millable

Representation of a Complex Number

Objects of this class represent complex numbers defined on one side or the other of the EL (exponential-log) plane. Numbers on "log" side are in polar form {r,theta,k), while numbers on the "exponential" side are in cartesian form (x,y).
The pair of two peer points (one on each side of the plane) is called a "pair".
The class Complex is a subclass of Item, with instance fields for the real part, side, and, if appropriate, the imaginary part, and possibly the branch.

Since:
V_0_3 // TODO The parsing of expressions to create Complex numbers is not very good at the moment. In particular, there must be a space following the "i" operator. Various other problems too. Needs to be fixed! // TODO This class needs significantly more testing.
Version:
$Revision: 1.27 $
Author:
Robin Hillyard
See Also:
Serialized Form

Nested Class Summary
private  class Complex.ComplexException
           
 
Field Summary
private  int _Branch
          If this Complex is defined on the polar (logarithmic) side, then this integer represents which "branch" the number is defined on.
private  boolean _Constant
          This instance field signifies if this instance of Complex has been designated a constant.
private  Value _I
          The Value instance representing the imaginary part of this Complex.
private  java.lang.String _Identifier
           
private  boolean _Polar
          Which side of the EL plane is the number defined on.
private  Value _R
          The Value instance representing the real part of this Complex.
static Complex $0
          The constant value of 0 (Cartesian/Exponential side).
static Complex $1
          The constant real value of 1 (Cartesian/Exponential side).
static Complex $I
          The constant imaginary value of 1 (Cartesian/Exponential side).
 
Fields inherited from class com.rubecula.util.Item
JQUANTITY_TEST
 
Constructor Summary
Complex()
          Secondary constructor for a zero-valued real-only cartesian Complex instance.
Complex(boolean polar)
          Secondary constructor for a zero-valued real-only Complex instance which, if polar, is defined on the primary branch (k=0).
Complex(boolean polar, java.lang.String identifier)
          Secondary constructor for a zero-valued real-only Complex instance which, if polar, is defined on the primary branch (k=0).
Complex(java.lang.String identifier)
          Secondary constructor for a zero-valued real-only cartesian Complex instance.
Complex(Value r)
          Secondary constructor for a real-only cartesian Complex instance.
Complex(Value r, boolean polar)
          Secondary constructor for a real-only Complex instance which, if polar, is defined on the primary branch (k=0).
Complex(Value r, boolean polar, java.lang.String identifier)
          Secondary constructor for a real-only Complex instance which, if polar, is defined on the primary branch (k=0).
Complex(Value r, java.lang.String identifier)
          Secondary constructor for a real-only cartesian Complex instance.
Complex(Value r, Value i)
          Secondary constructor for a Complex instance which, if polar, is defined on the primary branch (k=0).
Complex(Value r, Value i, boolean polar)
          Secondary constructor for a Complex instance which, if polar, is defined on the primary branch (k=0).
Complex(Value r, Value i, boolean polar, int k, java.lang.String identifier)
          Primary constructor for a Complex instance.
Complex(Value r, Value i, boolean polar, java.lang.String identifier)
          Secondary constructor for a Complex instance which, if polar, is defined on the primary branch (k=0).
Complex(Value r, Value i, java.lang.String identifier)
          Secondary constructor for a Complex instance which, if polar, is defined on the primary branch (k=0).
 
Method Summary
 void add(Complex addend)
          MUTATING Instance method to add a Complex into this object.
 Trigonometrical arctanX2()
          Method to evaluate the arctangent function.
protected  void assertMutable()
          This method tests whether this particular instance is mutable, i.e. it has not been designated a constant.
 java.lang.String audit(java.lang.String label)
          Method to return a detailed string from an arithmetical object for debugging purposes.
private  void cast(boolean polar)
          MUTATING Method to force a Complex to the opposite side of the plane, thus moving the point so that the real and imaginary values do not change numerically (other than possible factoring).
 java.lang.Object clone()
          Creates and returns a copy of this object.
 int compareTo(Complex val)
          Compares this Complex with the specified Complex.
protected  int compareTo(Complex val, boolean strict)
          Compares this Complex with the specified Complex.
 Imaginable complement()
          Method to determine the complex complement (i.e. the conjugate) of this Imaginable.
private  void convert(boolean polar)
          MUTATING Method to convert a Complex to the opposite side of the plane, keeping the point static, thus requiring that the real and imaginary values do change numerically.
 Complex convertValue(boolean polar)
          Method to yield an equivalent Complex instance to this, but where the "side" is defined by polar.
 Complex difference(Complex subtrahend)
          Method to yield the difference of this less subtrahend.
 double doubleValue()
          Returns the magnitude of this Complex as a double.
 Trigonometrical exp()
          Method to evaluate the exponential function.
 Divisible factored(double factor)
          Method to yield the quotient of this divided by factor, and return it as the result.
 Complex factored(Rational factor)
          Method to yield the quotient of this divided by factor, and return it as the result.
 java.lang.String getIdentifier()
          Method to get the specific identifier for an object.
(package private)  Value getImaginary()
          Package-scope method to get only the real part of the Complex.
(package private)  Value getReal()
          Package-scope method to get only the real part of the Complex.
 Divisible inverse()
          Method to yield the reciprocal of this and return it as the result.
(package private)  boolean isImaginary()
          Method to determine if this Complex is purely imaginary.
 boolean isMutable()
          This method indicates whether this particular instance is mutable, i.e.
 boolean isNormal()
          Method to determine if this instance is already normalized.
 boolean isPolar()
          Method to determine if this instance is defined on the polar (log) side as opposed to being defined on the exponential (cartesian) side.
 boolean isReal()
          Method to determine if this Complex is purely real.
 Trigonometrical log()
          Method to evaluate the natural log function.
 Value magnitude()
          Method to determine the magnitude of this Imaginable.
static void main(java.lang.String[] args)
          Main method for testing this class.
 Presentable makePresentableInstance(Presentation presentation)
          Instance method to convert a Presentation into a Presentable.
 Complex minus()
          Method to determine the negated value of this.
 void multiply(Complex multiplicand)
          MUTATING Instance method to multiply another Arithmetical into this object.
 void negate()
          MUTATING Instance method to negate this.
 void normalize()
          MUTATING instance method to normalize this object.
static Presentable Parse(Presentation presentation)
          Create a Complex from a Presentation and return it as a Presentable.
static Presentable Parse(Presentation presentation, java.lang.String identifier)
          Create an explicitly identified Complex from a Presentation and return it as a Presentable.
static Complex Parse(SymbolicPresentation presentation, java.lang.String identifier)
          Translates the SymbolicPresentation representation of a complex number into a Complex.
 Value phase()
          Method to determine the phase, also known as the argument, of this Imaginable.
 Complex pow(BaseNumber power)
          Method to yield this raised to the power specified.
 Complex pow(Complex power)
          Method to yield this raised to the power specified.
 Complex pow(double power)
          Method to yield this raised to the power specified.
 Complex pow(int power)
          Method to yield this raised to the power specified.
 Complex pow(Item power)
          Method to yield this raised to the power specified.
 Presentation present(AttrMap attributes)
          Convert this Presentable object into a Presentation, according to the set of attributes provided.
 Complex product(Complex multiplicand)
          Method to yield the product of this and multiplicand.
 Divisible quotient(BaseNumber divisor)
          Method to divide this by divisor and return the quotient as the result.
 void raiseToPower(double power)
          MUTATING Instance method to raise this to power x.
 void raiseToPower(int power)
          MUTATING Instance method to raise this to power x.
 Imaginable rotate(Value angle)
          Method to rotate this (in Complex space).
 void scale(long factor)
          MUTATING Instance method to multiply this by a scale factor.
 Mutable setConstant()
          This method sets this instance to be a constant, i.e. immutable.
 void setIdentifier(java.lang.String identifier)
          MUTATING Method to set a specific identifier to an object.
 Complex square()
          Method to yield the square of this.
 Complex sum(Complex addend)
          Method to yield the sum of this and addend.
 Trigonometrical tan_theta_2()
          Method to evaluate the tangent function.
static Complex valueOf(BaseNumber number)
          Factory method to create a real-valued Complex from a BaseNumber.
static Complex valueOf(java.lang.String string)
          Translates the String representation of a Complex into a Complex.
 
Methods inherited from class com.rubecula.util.Item
audit, audit, compareTo, Debug, getClassNameShort, getType, IsDebug, present, SetDebug, test, test, toString, Wrap
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.rubecula.util.Auditable
audit, audit
 

Field Detail

$0

public static final Complex $0
The constant value of 0 (Cartesian/Exponential side).


$1

public static final Complex $1
The constant real value of 1 (Cartesian/Exponential side).


$I

public static final Complex $I
The constant imaginary value of 1 (Cartesian/Exponential side).


_Identifier

private java.lang.String _Identifier

_R

private Value _R
The Value instance representing the real part of this Complex. Must be non-null.


_I

private Value _I
The Value instance representing the imaginary part of this Complex. May be null.


_Polar

private boolean _Polar
Which side of the EL plane is the number defined on. True for the polar (logarithmic) side, false for the cartesian (exponential) side.


_Branch

private int _Branch
If this Complex is defined on the polar (logarithmic) side, then this integer represents which "branch" the number is defined on. Otherwise, the branch is irrelevant (unless the number is cast to a polar value.


_Constant

private boolean _Constant
This instance field signifies if this instance of Complex has been designated a constant.

Constructor Detail

Complex

public Complex(Value r,
               Value i,
               boolean polar,
               int k,
               java.lang.String identifier)
Primary constructor for a Complex instance.

Parameters:
r - A Value defining the real part of the new Complex. (x or r).
i - A Value defining the imaginary part of the Complex (y or theta).
polar - True if this Complex is defined on the log side, i.e. as exp(r + i theta + 2 k pi); false if this number is defined on the exponential side, i.e. x = i y;
k - The "branch" on which this number is defined.
identifier - The name of this instance (or null).

Complex

public Complex(Value r,
               Value i,
               boolean polar,
               java.lang.String identifier)
Secondary constructor for a Complex instance which, if polar, is defined on the primary branch (k=0).

Parameters:
r - A Value defining the real part of the new Complex. (x or r).
i - A Value defining the imaginary part of the Complex (y or theta).
polar - True if this Complex is defined on the log side, i.e. as exp(r + i theta).
identifier - The name of this instance (or null).

Complex

public Complex(Value r,
               Value i,
               java.lang.String identifier)
Secondary constructor for a Complex instance which, if polar, is defined on the primary branch (k=0).

Parameters:
r - A Value defining the real part of the new Complex. (x or r).
i - A Value defining the imaginary part of the Complex (y or theta).
identifier - The name of this instance (or null).

Complex

public Complex(Value r,
               boolean polar,
               java.lang.String identifier)
Secondary constructor for a real-only Complex instance which, if polar, is defined on the primary branch (k=0).

Parameters:
r - A Value defining the real part of the new Complex. (x or r).
polar - True if this Complex is defined on the log side, i.e. as exp(r).
identifier - The name of this instance (or null).

Complex

public Complex(Value r,
               java.lang.String identifier)
Secondary constructor for a real-only cartesian Complex instance. The resulting instance will be behave exactly like the Rational object from which it is copied.

Parameters:
r - A Value defining the real part of the new Complex. (x or r).
identifier - The name of this instance (or null).

Complex

public Complex(boolean polar,
               java.lang.String identifier)
Secondary constructor for a zero-valued real-only Complex instance which, if polar, is defined on the primary branch (k=0).

Parameters:
polar - True if this Complex is defined on the log side, i.e. as exp(0).
identifier - The name of this instance (or null).

Complex

public Complex(java.lang.String identifier)
Secondary constructor for a zero-valued real-only cartesian Complex instance.

Parameters:
identifier - The name of this instance (or null).

Complex

public Complex(Value r,
               Value i,
               boolean polar)
Secondary constructor for a Complex instance which, if polar, is defined on the primary branch (k=0).

Parameters:
r - A Value defining the real part of the new Complex. (x or r).
i - A Value defining the imaginary part of the Complex (y or theta).
polar - True if this Complex is defined on the log side, i.e. as exp(r + i theta).

Complex

public Complex(Value r,
               Value i)
Secondary constructor for a Complex instance which, if polar, is defined on the primary branch (k=0).

Parameters:
r - A Value defining the real part of the new Complex. (x or r).
i - A Value defining the imaginary part of the Complex (y or theta).

Complex

public Complex(Value r,
               boolean polar)
Secondary constructor for a real-only Complex instance which, if polar, is defined on the primary branch (k=0).

Parameters:
r - A Value defining the real part of the new Complex. (x or r).
polar - True if this Complex is defined on the log side, i.e. as exp(r).

Complex

public Complex(Value r)
Secondary constructor for a real-only cartesian Complex instance. The resulting instance will be behave exactly like the Rational object from which it is copied.

Parameters:
r - A Value defining the real part of the new Complex. (x or r).

Complex

public Complex(boolean polar)
Secondary constructor for a zero-valued real-only Complex instance which, if polar, is defined on the primary branch (k=0).

Parameters:
polar - True if this Complex is defined on the log side, i.e. as exp(0).

Complex

public Complex()
Secondary constructor for a zero-valued real-only cartesian Complex instance.

Method Detail

Parse

public static Presentable Parse(Presentation presentation,
                                java.lang.String identifier)
                         throws PresentationException
Create an explicitly identified Complex from a Presentation and return it as a Presentable.

Parameters:
presentation - A presentation which should be parsed to form a Presentable.
identifier - the explicit identifier for the new Complex
Returns:
A Complex which corresponds to the presentation.
Throws:
PresentationException - if the presentation cannot be parsed as a Presentable object.

Parse

public static Presentable Parse(Presentation presentation)
                         throws PresentationException
Create a Complex from a Presentation and return it as a Presentable.

Parameters:
presentation - A presentation which should be parsed to form a Presentable.
Returns:
A Complex which corresponds to the presentation.
Throws:
PresentationException - if the presentation cannot be parsed as a Presentable object.

Parse

public static Complex Parse(SymbolicPresentation presentation,
                            java.lang.String identifier)
                     throws PresentationException
Translates the SymbolicPresentation representation of a complex number into a Complex. The presentation consists of a SymbolicPresentation or NumberPresentation, optionally followed by the string "i" and a SymbolicPresentation or NumberPresentation.

Parameters:
presentation - SymbolicPresentation representation of a complex number.
identifier - A string with which to identify this Complex.
Returns:
Complex : a new object derived from presentation.
Throws:
PresentationException - if the presentation cannot be parsed as a Complex object.

valueOf

public static Complex valueOf(BaseNumber number)
Factory method to create a real-valued Complex from a BaseNumber.

Parameters:
number - a number for which we require the (widened) Complex.
Returns:
the Complex, widened from number.

valueOf

public static Complex valueOf(java.lang.String string)
                       throws PresentationException
Translates the String representation of a Complex into a Complex.

Parameters:
string - String representation of Complex in the form: x + i y or r, z pi.
Returns:
Complex : a new object widened from the string string.
Throws:
PresentationException - if the string cannot be parsed as a Complex object.

getIdentifier

public java.lang.String getIdentifier()
Method to get the specific identifier for an object.

Specified by:
getIdentifier in interface Identifiable
Returns:
the identifier.

setIdentifier

public void setIdentifier(java.lang.String identifier)
MUTATING Method to set a specific identifier to an object.

Specified by:
setIdentifier in interface Nameable
Parameters:
identifier - the identifier to associate with the object.

clone

public java.lang.Object clone()
Creates and returns a copy of this object.

Returns:
a clone of this instance.
Throws:
RationalException - : Rational not Cloneable (should be impossible)
See Also:
Cloneable

compareTo

protected int compareTo(Complex val,
                        boolean strict)
Compares this Complex with the specified Complex.

Parameters:
val - Complex to which this Complex is to be compared.
strict - If strict is true, then the Complex objects are compared field by field; if false then the two objects are normalized if necessary before making the comparison. Apparent equality is then (in the non-strict case) more of an equivalency.
Returns:
-1, 0 as this Complex is not equal to, or is equal to val.

compareTo

public int compareTo(Complex val)
Compares this Complex with the specified Complex.

Parameters:
val - Complex to which this Complex is to be compared.
Returns:
-1, 0 as this Complex is not equal to, or is equal to val.

normalize

public void normalize()
MUTATING instance method to normalize this object. Repeated applications of this method on an object should have no effect. The effective value of this object before and after normalization must be the same.

Specified by:
normalize in interface Normalizable

isNormal

public boolean isNormal()
Description copied from interface: Normalizable
Method to determine if this instance is already normalized.

Specified by:
isNormal in interface Normalizable
Returns:
true if this object is already normalized.

audit

public java.lang.String audit(java.lang.String label)
Method to return a detailed string from an arithmetical object for debugging purposes.

Specified by:
audit in interface Auditable
Parameters:
label - String: the label to associate with the data
Returns:
the detailed string.

makePresentableInstance

public Presentable makePresentableInstance(Presentation presentation)
                                    throws PresentationException
Instance method to convert a Presentation into a Presentable. Ideally, this would be a class method, but such a method cannot be defined in an interface. Nor can it be defined in an abstract class with the intention of overriding it in a subclass. Polymorphism just doesn't work that way.
Therefore, the present value (as in fields) of the instance is essentially ignored - only the methods are important.

Specified by:
makePresentableInstance in interface Presentable
Parameters:
presentation - of a number to be converted into a Presentable number.
Returns:
a Complex in the form of a Presentable.
Throws:
PresentationException - if presentation cannot be parsed appropriately.

present

public Presentation present(AttrMap attributes)
                     throws PresentationException
Convert this Presentable object into a Presentation, according to the set of attributes provided.

Specified by:
present in interface Presentable
Parameters:
attributes - a map of the required attributes for the presentation. Supported attributes include:
Normalize
String On / Off*;
Tolerance
Double/String value (def: 0);
NYI: Places
Integer/String the number of decimal places to show
NYI: Round
String On * / Off
NYI: Radix
Integer/String the value of the radix
NYI: Zero
String On * / Off where to show 0.x or just .x
NYI: Decimal
String "." or ","
Returns:
an appropriate instance of Presentation.
Throws:
PresentationException - if this object cannot be presented with the given attributes.

inverse

public Divisible inverse()
Method to yield the reciprocal of this and return it as the result.
NOTE: it is a requirement of this method that the class of the result is the same as the class of this so that the result can be safely cast to the original class.

Specified by:
inverse in interface Divisible
Returns:
the reciprocal of this.

quotient

public Divisible quotient(BaseNumber divisor)
                   throws InvalidOperandException
Method to divide this by divisor and return the quotient as the result.
NOTE: it is a requirement of this method that the class of the result is the same as the class of this so that the result can be safely cast to the original class.

Specified by:
quotient in interface Divisible
Parameters:
divisor - the number to multiply by this.
Returns:
the quotient of this divided by divisor.
Throws:
InvalidOperandException - operands are not compatible for the quotient operation.

factored

public Divisible factored(double factor)
Method to yield the quotient of this divided by factor, and return it as the result.
NOTE: it is a requirement of this method that the class of the result is the same as the class of this so that the result can be safely cast to the original class. // TODO This factors the stored values, and is therefore yields a different result from using quotient. Check that this behavior is appropriate.

Specified by:
factored in interface Divisible
Parameters:
factor - the scale factor.
Returns:
the quotient of this divided by factor.

exp

public Trigonometrical exp()
Method to evaluate the exponential function. This method is the inverse of log().

Specified by:
exp in interface Trigonometrical
Returns:
e(this) in the form of a Rational.

log

public Trigonometrical log()
Method to evaluate the natural log function. This method is the inverse of exp().

Specified by:
log in interface Trigonometrical
Returns:
log(this) in the form of a Rational or an Approximation.

arctanX2

public Trigonometrical arctanX2()
Method to evaluate the arctangent function. This method is the inverse of tan_theta_2().

Specified by:
arctanX2 in interface Trigonometrical
Returns:
2 * atan(this) in the form of a Rational.

tan_theta_2

public Trigonometrical tan_theta_2()
Method to evaluate the tangent function. This method is the inverse of arctanX2().

Specified by:
tan_theta_2 in interface Trigonometrical
Returns:
tan(this/2) in the form of a Rational.

getReal

Value getReal()
Package-scope method to get only the real part of the Complex.

Returns:
the real part as a Value.

getImaginary

Value getImaginary()
Package-scope method to get only the real part of the Complex.

Returns:
the imaginary part as a Value (or null).

isReal

public boolean isReal()
Method to determine if this Complex is purely real. Typically used to avoid NPE exceptions when accessing the imaginary part of a Complex object.

Returns:
true if the imaginary part is non-existent or zero.

isImaginary

boolean isImaginary()
Method to determine if this Complex is purely imaginary.

Returns:
true if the real part is zero (Cartesian) or unity (Polar).

isPolar

public boolean isPolar()
Method to determine if this instance is defined on the polar (log) side as opposed to being defined on the exponential (cartesian) side.

Returns:
the value of _Polar.

factored

public Complex factored(Rational factor)
Method to yield the quotient of this divided by factor, and return it as the result.

Parameters:
factor - the scale factor.
Returns:
the quotient of this divided by factor.

magnitude

public Value magnitude()
Method to determine the magnitude of this Imaginable.

Specified by:
magnitude in interface Imaginable
Returns:
the magnitude.

phase

public Value phase()
Method to determine the phase, also known as the argument, of this Imaginable.

Specified by:
phase in interface Imaginable
Returns:
the phase as a multiple of pi.

doubleValue

public double doubleValue()
Returns the magnitude of this Complex as a double. This may involve rounding.

Returns:
the numeric value of the magnitude of this object after conversion to type double.

complement

public Imaginable complement()
Method to determine the complex complement (i.e. the conjugate) of this Imaginable.

Specified by:
complement in interface Imaginable
Returns:
An Imaginable which is equivalent in magnitude as this, but with phase that is the negative of this.

rotate

public Imaginable rotate(Value angle)
Method to rotate this (in Complex space). The resulting value has the same magnitude as this, but has a phase with is incremented by phase.

Specified by:
rotate in interface Imaginable
Parameters:
angle - the angle by which this is to be rotated (counter-clockwise).
Returns:
An Imaginable which is equivalent in magnitude as this, but with phase that is the negative of this.

product

public Complex product(Complex multiplicand)
Method to yield the product of this and multiplicand.

Parameters:
multiplicand - the Complex which is to be multiplied by this
Returns:
a copy of this which has undergone multiply(Complex) with argument multiplicand.
Throws:
Complex.ComplexException - product(multiplicand): logic error

sum

public Complex sum(Complex addend)
Method to yield the sum of this and addend.

Parameters:
addend - the Complex which is to be multiplied by this
Returns:
a copy of this which has undergone add(Complex)with argument addend.
Throws:
Complex.ComplexException - sum(addend): logic error

difference

public Complex difference(Complex subtrahend)
Method to yield the difference of this less subtrahend.

Parameters:
subtrahend - the Complex which is to be subtracted from this
Returns:
the resulf of applying minus()to subtrahend and then passing this to sum(Complex).

minus

public Complex minus()
Method to determine the negated value of this.

Returns:
a copy of this on which negate()has been invoked.

square

public Complex square()
Method to yield the square of this.

Returns:
the product(Complex)of this with this.

pow

public Complex pow(Item power)
            throws InvalidOperandException
Method to yield this raised to the power specified.

Parameters:
power - the (Item) power to which this is to be raised.
Returns:
pow(Complex)if power is a Complex; pow(BaseNumber)if power is a BaseNumber; else throw exception.
Throws:
ComplexException(pow(Item): - not available for power class
InvalidOperandException

pow

public Complex pow(Complex power)
            throws InvalidOperandException
Method to yield this raised to the power specified.

Parameters:
power - the (Complex) power to which this is to be raised.
Returns:
if this is real and the real part is "e" and the power is not polar, then return a copy of this which has been cast as polar; else throw an InvalidOperandException
Throws:
InvalidOperandException - Complex.pow(Complex): not implemented for this combination

pow

public Complex pow(int power)
Method to yield this raised to the power specified.

Parameters:
power - the (int) power to which this is to be raised.
Returns:
this if power==1 else $1 if power==0 else square()if power==2 else return a copy that has undergone raiseToPower(int).

pow

public Complex pow(double power)
Method to yield this raised to the power specified.

Parameters:
power - the (double) power to which this is to be raised.
Returns:
this if power==1 else $1 if power==0 else square()if power==2 else return a copy that has undergone raiseToPower(double).

pow

public Complex pow(BaseNumber power)
Method to yield this raised to the power specified.

Parameters:
power - the power to which this is to be raised (a BaseNumber)
Returns:
result of pow(int) given power.intValue() or pow(double) given power.doubleValue() if power is not an integer.

cast

private void cast(boolean polar)
MUTATING Method to force a Complex to the opposite side of the plane, thus moving the point so that the real and imaginary values do not change numerically (other than possible factoring).

Parameters:
polar - the side of the plane to which this Complex is to be moved.

convert

private void convert(boolean polar)
MUTATING Method to convert a Complex to the opposite side of the plane, keeping the point static, thus requiring that the real and imaginary values do change numerically. If this is a real value (no imaginary part) then this operation is a noop.

Parameters:
polar - the side of the plane to which this Complex is to be converted.

setConstant

public Mutable setConstant()
This method sets this instance to be a constant, i.e. immutable. Future calls to the isMutable() method will yield false.

Specified by:
setConstant in interface Mutable
Returns:
as a convenience this method returns itself.

isMutable

public boolean isMutable()
This method indicates whether this particular instance is mutable, i.e. it has not been designated a constant.

Specified by:
isMutable in interface Mutable
Returns:
true if this instance can be mutated, otherwise false (it is constant).

assertMutable

protected void assertMutable()
This method tests whether this particular instance is mutable, i.e. it has not been designated a constant. If it is not mutable, an RuntimeException is thrown. // TODO instead generate an assertion exception (or some other kind of runtime exception).


add

public void add(Complex addend)
         throws InvalidOperandException
MUTATING Instance method to add a Complex into this object.

Parameters:
addend - the number to add to this.
Throws:
InvalidOperandException - operands are not compatible for the add operation.

multiply

public void multiply(Complex multiplicand)
              throws InvalidOperandException
MUTATING Instance method to multiply another Arithmetical into this object.

Parameters:
multiplicand - the number by which this is to be multiplied.
Throws:
InvalidOperandException - operands are not compatible for the multiply operation.

negate

public void negate()
MUTATING Instance method to negate this.


raiseToPower

public void raiseToPower(int power)
MUTATING Instance method to raise this to power x.

Parameters:
power - the number of times this should be multiplied by itself.

raiseToPower

public void raiseToPower(double power)
MUTATING Instance method to raise this to power x.

Parameters:
power - the number of times this should be multiplied by itself.

scale

public void scale(long factor)
MUTATING Instance method to multiply this by a scale factor. This method parallels the method defined in Arithmutable. Note that under this operation, the scaling (multiplication) is always directly on the stored value in this regardless of values of other fields. So, for example, if a Complex which is defined on the polar/log side is scaled by two, the result will be the equivalent of squaring the pair number on the cartesian/exp side.

Parameters:
factor - the scale factor.

convertValue

public Complex convertValue(boolean polar)
Method to yield an equivalent Complex instance to this, but where the "side" is defined by polar.

Parameters:
polar - true if the result is required to be on the log side or false for the exponential (cartesian) side.
Returns:
either this or a copy of this which has been subject to convert(boolean).

main

public static void main(java.lang.String[] args)
Main method for testing this class.

Parameters:
args - String[] : the command line options.