public class Apcomplex extends Number implements Formattable, Serializable
Apfloat.
Note that although the Apcomplex class extends Number,
the methods inherited from Number return the value of
the real part of the complex number. Thus they are more meaningful
for the Apfloat class and its subclasses.
Apfloat,
ApcomplexMath,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT
Default precision.
|
static Apcomplex |
I
Imaginary unit.
|
static long |
INFINITE
Infinite precision or scale.
|
static Apint |
ONE
Constant for one.
|
static Apint |
ZERO
Constant for zero.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Apcomplex()
Default constructor.
|
|
Apcomplex(Apfloat real)
Construct a real apcomplex whose imaginary part is zero.
|
|
Apcomplex(Apfloat real,
Apfloat imag)
Construct an apcomplex with the specified real and imaginary part.
|
|
Apcomplex(PushbackReader in)
Reads an apcomplex from a reader.
|
|
Apcomplex(String value)
Constructs an apcomplex from a string.
|
| Modifier and Type | Method and Description |
|---|---|
Apcomplex |
add(Apcomplex z)
Adds two apcomplex numbers.
|
byte |
byteValue()
Returns the value of the this number as a
byte. |
Apcomplex |
conj()
Returns the complex conjugate of this apcomplex.
|
Apcomplex |
divide(Apcomplex z)
Divides two apcomplex numbers.
|
double |
doubleValue()
Returns the value of the this number as a
double. |
long |
equalDigits(Apcomplex z)
Computes number of equal digits.
|
boolean |
equals(Object obj)
Compares this object to the specified object.
|
float |
floatValue()
Returns the value of the this number as a
float. |
void |
formatTo(Formatter formatter,
int flags,
int width,
int precision)
Formats the object using the provided formatter.
|
int |
hashCode()
Returns a hash code for this apcomplex.
|
Apfloat |
imag()
Returns the imaginary part of this apcomplex.
|
int |
intValue()
Returns the value of the this number as an
int. |
long |
longValue()
Returns the value of the this number as a
long. |
Apcomplex |
multiply(Apcomplex z)
Multiplies two apcomplex numbers.
|
Apcomplex |
negate()
Negative value.
|
long |
precision()
Returns the precision of this apcomplex.
|
Apcomplex |
precision(long precision)
Returns an apcomplex with the same value as this apcomplex accurate to the
specified precision.
|
int |
radix()
Radix of this apcomplex.
|
Apfloat |
real()
Returns the real part of this apcomplex.
|
long |
scale()
Returns the scale of this apcomplex.
|
short |
shortValue()
Returns the value of the this number as a
short. |
long |
size()
Returns the size of this apcomplex.
|
Apcomplex |
subtract(Apcomplex z)
Subtracts two apcomplex numbers.
|
Apcomplex |
toRadix(int radix)
Convert this apcomplex to the specified radix.
|
String |
toString()
Returns a string representation of this apcomplex.
|
String |
toString(boolean pretty)
Returns a string representation of this apcomplex.
|
void |
writeTo(Writer out)
Write a string representation of this apcomplex to a
Writer. |
void |
writeTo(Writer out,
boolean pretty)
Write a string representation of this apcomplex to a
Writer. |
public static final Apint ZERO
ZERO
in all addition, subtraction, multiplication, division and
comparison operations regardless of the radix used.public static final Apint ONE
ONE
in all multiplication, division and equality comparison operations
regardless of the radix used. However, in subtraction and addition
it only works with numbers in the same radix.public static final Apcomplex I
Apcomplex(ZERO, ONE).
It is safe to use I in all multiplication,
division and equality comparison operations
regardless of the radix used. In addition and subtraction
it only works with numbers in the same radix.public static final long INFINITE
public static final long DEFAULT
protected Apcomplex()
public Apcomplex(Apfloat real)
real - The real part of the number.public Apcomplex(Apfloat real, Apfloat imag) throws IllegalArgumentException
real - The real part of the number.imag - The imaginary part of the number.IllegalArgumentException - If the real part and imaginary part are not zero but have different radixes.public Apcomplex(String value) throws NumberFormatException, ApfloatRuntimeException
The input must be of one of the formats
realPart
"(" [whitespace] realPart [whitespace] ")"
"(" [whitespace] realPart [whitespace] "," [whitespace] imaginaryPart [whitespace] ")"
value - The input string.NumberFormatException - If the number is invalid.ApfloatRuntimeExceptionpublic Apcomplex(PushbackReader in) throws IOException, NumberFormatException, ApfloatRuntimeException
PushbackReader so that the invalid character can
be returned back to the stream.The input must be of one of the formats
realPart
"(" [whitespace] realPart [whitespace] ")"
"(" [whitespace] realPart [whitespace] "," [whitespace] imaginaryPart [whitespace] ")"
in - The input stream.IOException - In case of I/O error reading from the stream.NumberFormatException - If the number is invalid.ApfloatRuntimeExceptionpublic int radix()
public Apfloat real()
public Apfloat imag()
public Apcomplex conj() throws ApfloatRuntimeException
x - i y, where this apcomplex is x + i y.ApfloatRuntimeExceptionpublic long precision()
throws ApfloatRuntimeException
ApfloatRuntimeExceptionpublic Apcomplex precision(long precision) throws IllegalArgumentException, ApfloatRuntimeException
If the requested precision less than this number's current precision, the functionality is quite obvious: the precision is simply truncated, and e.g. comparison and equality checking will work as expected. Some rounding errors in e.g. addition and subtraction may still occur, as "invisible" trailing digits can remain in the number.
If the requested precision more than this number's current precision, the functionality is quite undefined: the digits up to this number's current precision are guaranteed to be the same, but the "new" digits are undefined: they may be zero, or they may be digits that have been previously discarded with a call to precision() with a smaller number of digits, or they may be something else, or any combination of these.
These limitations allow various performance optimizations to be made.
precision - Precision of the new apcomplex.IllegalArgumentException - If precision is <= 0.ApfloatRuntimeExceptionpublic long scale()
throws ApfloatRuntimeException
Zero has a scale of -INFINITE.
ApfloatRuntimeExceptionApfloat.scale()public long size()
throws ApfloatRuntimeException
Zero has a size of 0.
ApfloatRuntimeExceptionApfloat.size()public Apcomplex negate() throws ApfloatRuntimeException
-this.ApfloatRuntimeExceptionpublic Apcomplex add(Apcomplex z) throws ApfloatRuntimeException
z - The number to be added to this number.this + z.ApfloatRuntimeExceptionpublic Apcomplex subtract(Apcomplex z) throws ApfloatRuntimeException
z - The number to be subtracted from this number.this - z.ApfloatRuntimeExceptionpublic Apcomplex multiply(Apcomplex z) throws ApfloatRuntimeException
z - The number to be multiplied by this number.this * z.ApfloatRuntimeExceptionpublic Apcomplex divide(Apcomplex z) throws ArithmeticException, ApfloatRuntimeException
z - The number by which this number is to be divided.this / z.ArithmeticException - In case the divisor is zero.ApfloatRuntimeExceptionpublic double doubleValue()
double.
Only takes the real part of this number.doubleValue in class Numberdouble.Apfloat.doubleValue()public float floatValue()
float.
Only takes the real part of this number.floatValue in class Numberfloat.Apfloat.floatValue()public byte byteValue()
byte.
Only takes the real part of this number.byteValue in class Numberbyte.Apfloat.byteValue()public short shortValue()
short.
Only takes the real part of this number.shortValue in class Numbershort.Apfloat.shortValue()public int intValue()
int.
Only takes the real part of this number.intValue in class Numberint.Apfloat.intValue()public long longValue()
long.
Only takes the real part of this number.longValue in class Numberlong.Apfloat.longValue()public long equalDigits(Apcomplex z) throws ApfloatRuntimeException
Compares the digits of the numbers starting from the most significant digits. The exponent and sign are taken into consideration, so if either one doesn't match, the numbers are considered to have zero equal digits.
For example, the numbers (12345, 123) and (123456, 12) have zero matching digits, and the numbers (12345, 12) and (12355, 13) have three matching digits.
z - Number to compare with.ApfloatRuntimeExceptionpublic Apcomplex toRadix(int radix) throws NumberFormatException, ApfloatRuntimeException
radix - The radix.NumberFormatException - If the radix is invalid.ApfloatRuntimeExceptionpublic boolean equals(Object obj)
Note: two apfloats are considered equal if they have an identical mantissa, but different precision.
public int hashCode()
public String toString()
public String toString(boolean pretty) throws ApfloatRuntimeException
pretty - true to use a fixed-point notation, false to use an exponential notation.ApfloatRuntimeExceptionpublic void writeTo(Writer out) throws IOException, ApfloatRuntimeException
Writer.out - The output Writer.IOException - In case of I/O error writing to the stream.ApfloatRuntimeExceptionpublic void writeTo(Writer out, boolean pretty) throws IOException, ApfloatRuntimeException
Writer.out - The output Writer.pretty - true to use a fixed-point notation, false to use an exponential notation.IOException - In case of I/O error writing to the stream.ApfloatRuntimeExceptionpublic void formatTo(Formatter formatter, int flags, int width, int precision)
formatTo in interface Formattableformatter - The formatter.flags - The flags to modify the output format.width - The minimum number of characters to be written to the output, or -1 for no minimum.precision - The maximum number of characters to be written to the output, or -1 for no maximum.Apfloat.formatTo(Formatter,int,int,int)Copyright © 2025. All rights reserved.