Package mandelbrot
Class Complex
- java.lang.Object
-
- mandelbrot.Complex
-
public class Complex extends java.lang.ObjectTheComplexclass represents a complex number. Complex numbers are immutable: their values cannot be changed after they are created. It includes methods for addition, subtraction, multiplication, division, conjugation, and other common functions on complex numbers.
-
-
Constructor Summary
Constructors Constructor Description Complex(double real, double imaginary)Initializes a complex number with the specified real and imaginary parts.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Complexadd(Complex addend)Returns aComplexwhose value is(this + addend).booleanequals(java.lang.Object other)Test for equality with another object.static Complexreal(double real)Creates a complex number with the specified real part and an imaginary part equal to zero.Complexscale(double lambda)Returns the scalar multiplication of this complex number.java.lang.StringtoString()Returns a string representation of this complex number.
-
-
-
Method Detail
-
real
public static Complex real(double real)
Creates a complex number with the specified real part and an imaginary part equal to zero.- Parameters:
real- the real component- Returns:
- the complex
real + 0i
-
add
public Complex add(Complex addend)
Returns aComplexwhose value is(this + addend).- Parameters:
addend- a complex- Returns:
- the complex number whose value is
this + addend
-
scale
public Complex scale(double lambda)
Returns the scalar multiplication of this complex number.- Parameters:
lambda- a scalar number- Returns:
- the complex number
lambda * this
-
equals
public boolean equals(java.lang.Object other)
Test for equality with another object. If both the real and imaginary parts of two complex numbers are considered equal according toHelpers.doubleCompare(i.e., withinHelpers.RANGE), the two Complex objects are considered to be equal.- Overrides:
equalsin classjava.lang.Object- Parameters:
other- Object to test for equality with this instance.- Returns:
trueif the objects are equal,falseif object isnull, not an instance ofComplex, or not equal to this instance.
-
toString
public java.lang.String toString()
Returns a string representation of this complex number.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of this complex number of the form 42.0 - 1024.0i.
-
-