Package nom.tam.util

Class ComplexValue

java.lang.Object
nom.tam.util.ComplexValue
Direct Known Subclasses:
ComplexValue.Float

public class ComplexValue extends Object

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

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Single-precision complex values.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static 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

    Constructors
    Constructor
    Description
    ComplexValue(double re, double im)
    Instantiates a new complex number value with the specified real and imaginary components.
    Instantiates a new complex number value from the string repressentation of it in a FITS header value.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    int
     
    final double
    im()
    Returns the imaginary part of this complex value.
    final boolean
    Checks if the complex value is finite.
    final boolean
    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(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.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • ZERO

      public static final ComplexValue ZERO
      The complex zero
    • ONE

      public static final ComplexValue ONE
      The complex unity along the real axis, or (1.0, 0.0)
    • I

      public static final ComplexValue 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 part
      im - thei maginary part
    • ComplexValue

      public ComplexValue(String text) throws IllegalArgumentException

      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 as 123.456 or 123 (as real-only values). There can be any number of spaces around the brackets, number components or the comma.

      If FitsFactory.setAllowHeaderRepairs(boolean) is set true, 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()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • isZero

      public final boolean isZero()
      Checks if the complex value is zero. That is, if both the real or imaginary parts are zero.
      Returns:
      trueif both the real or imaginary parts are zero. Otherwise false.
    • 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:
      trueif neither the real or imaginary parts are NaN or Infinite. Otherwise false.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String 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.
      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

      public String toBoundedString(int maxLength) throws LongValueException
      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.