Class ComplexValue
- Direct Known Subclasses:
ComplexValue.Float
A no-frills complex value, for representing complex numbers in FITS headers. It is a non-mutable object that is created with a real and imaginary parts, which can be retrieved thereafter, and provides string formatting that is suited specifically for representation in FITS headers.
Note that binary tables handle complex data differently, with elements of `float[2]` or `double[2]`.
- Since:
- 1.16
- Author:
- Attila Kovacs
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Single-precision complex values. -
Field Summary
Modifier and TypeFieldDescriptionstatic final ComplexValue
The unity along the imaginary axis i, or (0.0, 1.0)static final ComplexValue
The complex unity along the real axis, or (1.0, 0.0)static final ComplexValue
The complex zero -
Constructor Summary
ConstructorDescriptionComplexValue
(double re, double im) Instantiates a new complex number value with the specified real and imaginary components.ComplexValue
(String text) Instantiates a new complex number value from the string repressentation of it in a FITS header value. -
Method Summary
Modifier and TypeMethodDescriptionboolean
int
hashCode()
final double
im()
Returns the imaginary part of this complex value.final boolean
isFinite()
Checks if the complex value is finite.final boolean
isZero()
Checks if the complex value is zero.final double
re()
Returns the real part of this complex value.toBoundedString
(int maxLength) Converts this comlex value to its string representation using up to the specified number of characters only.toString()
toString
(int decimals) Converts this complex value to its string representation with up to the specified number of decimal places showing after the leading figure, for both the real and imaginary parts.
-
Field Details
-
ZERO
The complex zero -
ONE
The complex unity along the real axis, or (1.0, 0.0) -
I
The unity along the imaginary axis i, or (0.0, 1.0)
-
-
Constructor Details
-
ComplexValue
public ComplexValue(double re, double im) Instantiates a new complex number value with the specified real and imaginary components.- Parameters:
re
- the real partim
- thei maginary part
-
ComplexValue
Instantiates a new complex number value from the string repressentation of it in a FITS header value. By default, it will parse complex numbers as a comma-separated pair of real values enclosed in a bracket, such as
(1.0, -2.0)
, or standard real values, such as123.456
or123
(as real-only values). There can be any number of spaces around the brackets, number components or the comma.If
FitsFactory.setAllowHeaderRepairs(boolean)
is settrue
, the parsing becomes more tolerant, working around missing closing brackets, different number of comma-separated components, and missing empty components. So, for example(,-1,abc
may be parsed assuming it was meant to be -i.- Parameters:
text
- The FITS header value representing the complex number, in brackets with the real and imaginary pars separated by a comma. Additional spaces may surround the component parts.- Throws:
IllegalArgumentException
- if the supplied string does not appear to be a FITS standard representation of a complex value.- See Also:
-
-
Method Details
-
re
public final double re()Returns the real part of this complex value.- Returns:
- the real part
- See Also:
-
im
public final double im()Returns the imaginary part of this complex value.- Returns:
- the imaginary part
- See Also:
-
hashCode
public int hashCode() -
equals
-
isZero
public final boolean isZero()Checks if the complex value is zero. That is, if both the real or imaginary parts are zero.- Returns:
true
if both the real or imaginary parts are zero. Otherwisefalse
.
-
isFinite
public final boolean isFinite()Checks if the complex value is finite. That is, if neither the real or imaginary parts are NaN or Infinite.- Returns:
true
if neither the real or imaginary parts are NaN or Infinite. Otherwisefalse
.
-
toString
-
toString
Converts this complex value to its string representation with up to the specified number of decimal places showing after the leading figure, for both the real and imaginary parts.- Parameters:
decimals
- the maximum number of decimal places to show.- Returns:
- the string representation with the specified precision, which may be used in a FITS header.
- See Also:
-
toBoundedString
Converts this comlex value to its string representation using up to the specified number of characters only. The precision may be reduced as necessary to ensure that the representation fits in the allotted space.- Parameters:
maxLength
- the maximum length of the returned string representation- Returns:
- the string representation, possibly with reduced precision to fit into the alotted space.
- Throws:
LongValueException
- if the space was too short to fit the value even with the minimal (1-digit) precision.
-