Package mandelbrot
Class Complex
- java.lang.Object
-
- mandelbrot.Complex
-
public class Complex extends java.lang.Object
TheComplex
class 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 Complex
add(Complex addend)
Returns aComplex
whose value is(this + addend)
.boolean
equals(java.lang.Object other)
Test for equality with another object.static Complex
real(double real)
Creates a complex number with the specified real part and an imaginary part equal to zero.Complex
scale(double lambda)
Returns the scalar multiplication of this complex number.java.lang.String
toString()
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 aComplex
whose 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:
equals
in classjava.lang.Object
- Parameters:
other
- Object to test for equality with this instance.- Returns:
true
if the objects are equal,false
if 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:
toString
in classjava.lang.Object
- Returns:
- a string representation of this complex number of the form 42.0 - 1024.0i.
-
-