public final class Complex extends java.lang.Number implements java.lang.Comparable<Complex>
Modifier and Type | Field and Description |
---|---|
static int |
BYTES
size in bytes if converted to a byte array
|
static Complex |
ZERO |
Constructor and Description |
---|
Complex()
Constructor - new Complex variable without a value is 0.0/0.0
|
Complex(double real)
Constructor - construct a Complex number from a "real part"
|
Complex(double real,
double imag)
Constructor - construct a Complex number from a "real part" and
"imaginary part"
|
Modifier and Type | Method and Description |
---|---|
double |
abs()
abs() - return abs/modulus/magnitude
|
Complex |
add(Complex b)
add(b) - return a new Complex object whose value is (this + b)
|
java.math.BigInteger |
bigIntegerValue()
bigIntegerValue() - return a big integer from a Complex number
|
boolean |
booleanValue()
booleanValue() - return a (truncated) boolean from a Complex number
|
byte |
byteValue()
byteValue() - return a (truncated) byte from a Complex number
|
int |
compareTo(Complex x)
compareTo - compare two Complex numbers
|
Complex |
conjugate()
conjugate() - return a new Complex object whose value is the conjugate of this
|
Complex |
cos()
cos() - return a new Complex object whose value is the complex cosine of this
|
Complex |
divide(Complex b)
divide(b) - return a / b
|
double |
doubleValue()
doubleValue() - return a (truncated) double from a Complex number
|
boolean |
equals(java.lang.Object x)
equals - compare two Complex numbers for equality
|
Complex |
exp()
exp() - return a new Complex object whose value is the complex exponential of this
|
FixedBin |
fixedBinValue()
fixedBinValue() - return a (truncated) FixedBin from a Complex number
|
float |
floatValue()
floatValue() - return a (truncated) float from a Complex number
|
void |
fromBytes(byte[] bytes)
convert a byte array (from an I/O or Group assignment) to this Complex number
(making it mutable for the moment)
|
int |
hashCode() |
java.lang.Double |
imag()
imag() - return the imaginary part of athis complex number
|
double |
imagValue()
imagValue() - same as imag() but return primitive double
|
int |
intValue()
intValue() - return a (truncated) integer from a Complex number
|
long |
longValue()
longValue() - return a (truncated) long from a Complex number
|
static void |
main(java.lang.String[] args)
main - unit test for Complex
|
Complex |
multiply(Complex b)
multiply(b) - return a new Complex object whose value is (this * b)
|
Complex |
negate()
negate() - return a new Complex object whose value is -this
|
static Complex |
parseComplex(java.lang.String value)
parseComplex() - similar to valueOf(String) except throws traditional
NumberFormatException
|
double |
phase()
phase() - return angle/phase/argument, normalized to be between -pi and pi
|
java.lang.Double |
real()
real() - return the real part of this complex number
|
double |
realValue()
realValue() - same as real() but return primitive double
|
Complex |
reciprocal()
reciprical() - return a new Complex object whose value is the reciprocal of this
|
Complex |
scale(double alpha)
scale(a) - return a new object whose value is (this * alpha)
|
short |
shortValue()
shortValue() - return a (truncated) short from a Complex number
|
Complex |
sin()
sin() - return a new Complex object whose value is the complex sine of this
|
Complex |
subtract(Complex b)
subtract(b) - return a new Complex object whose value is (this - b)
|
Complex |
tan()
tan() - return a new Complex object whose value is the complex tangent of this
|
byte[] |
toBytes()
convert Complex to a byte array (for an I/O or Group assignment)
|
java.lang.String |
toString()
toString() - return a String representation of the invoking Complex object
|
static Complex |
valueOf(java.math.BigDecimal b)
valueOf() - construct a Complex number from a BigDecimal
|
static Complex |
valueOf(java.math.BigInteger b)
valueOf() - construct a Complex number from a BigInteger
|
static Complex |
valueOf(BitN bs)
valueOf() - construct a Complex number from a BitN
|
static Complex |
valueOf(java.lang.Boolean b)
valueOf() - construct a Complex number from a Boolean
|
static Complex |
valueOf(byte i)
valueOf() - construct a Complex number from a byte
|
static Complex |
valueOf(byte[] bytes)
valueOf() - construct a Complex number from a byte array
(use instead of fromBytes() because Complex is immutable)
|
static Complex |
valueOf(double d)
valueOf() - construct a Complex number from a double or float
|
static Complex |
valueOf(double real,
double imag)
valueOf() - construct a Complex number from a "real part" and
"imaginary part"
|
static Complex |
valueOf(FixedBin f)
valueOf() - construct a Complex number from a FixedBin
|
static Complex |
valueOf(int i)
valueOf() - construct a Complex number from an int
|
static Complex |
valueOf(long i)
valueOf() - construct a Complex number from a long
|
static Complex |
valueOf(short i)
valueOf() - construct a Complex number from a short
|
static Complex |
valueOf(java.lang.String str)
valueOf() - construct a Complex number from a string
|
public static final int BYTES
public static final Complex ZERO
public Complex()
public Complex(double real, double imag)
real
- imag
- public Complex(double real)
real
- public static Complex valueOf(double real, double imag)
real
- imag
- public static Complex valueOf(java.lang.String str)
str
- - a String in the same format as returned by toString()public static Complex parseComplex(java.lang.String value)
value
- - a String in the same format as returned by toString()public static Complex valueOf(long i)
i
- - a long representing the real partpublic static Complex valueOf(int i)
i
- - an int representing the real partpublic static Complex valueOf(short i)
i
- - a short representing the real partpublic static Complex valueOf(byte i)
i
- - a byte representing the real partpublic static Complex valueOf(double d)
d
- - a doublepublic static Complex valueOf(FixedBin f)
f
- - a FixedBinpublic static Complex valueOf(java.math.BigDecimal b)
b
- - a BigDecimalpublic static Complex valueOf(java.math.BigInteger b)
b
- - a BigIntegerpublic static Complex valueOf(java.lang.Boolean b)
b
- - a Booleanpublic static Complex valueOf(BitN bs)
bs
- - a BitNpublic static Complex valueOf(byte[] bytes)
bytes
- - a 16-byte byte arrayCONVERSION
- CONDITIONpublic java.lang.Double real()
public java.lang.Double imag()
public java.lang.String toString()
toString
in class java.lang.Object
public int intValue()
intValue
in class java.lang.Number
public short shortValue()
shortValue
in class java.lang.Number
public byte byteValue()
byteValue
in class java.lang.Number
public long longValue()
longValue
in class java.lang.Number
public java.math.BigInteger bigIntegerValue()
public double doubleValue()
doubleValue
in class java.lang.Number
public float floatValue()
floatValue
in class java.lang.Number
public boolean booleanValue()
public double realValue()
public double imagValue()
public FixedBin fixedBinValue()
public double abs()
public double phase()
public Complex negate()
public Complex add(Complex b)
b
- public Complex subtract(Complex b)
b
- public Complex multiply(Complex b)
b
- public Complex scale(double alpha)
alpha
- public Complex conjugate()
public Complex reciprocal()
public Complex divide(Complex b)
b
- Complex number as the divisorpublic Complex exp()
public Complex sin()
public Complex cos()
public Complex tan()
public void fromBytes(byte[] bytes)
bytes
- - the byte arrayfor the proper way to create new Complex numbers from bytes
public byte[] toBytes()
public boolean equals(java.lang.Object x)
equals
in class java.lang.Object
x
- - a Complex number to compareCONVERSION
- condition if x is not Complexpublic int compareTo(Complex x)
compareTo
in interface java.lang.Comparable<Complex>
x
- - a Complex number to compareCONVERSION
- condition if x is not Complexpublic int hashCode()
hashCode
in class java.lang.Object
public static void main(java.lang.String[] args)
args
- - the real & imaginary part of operand "a" and "b", respectively