Package complex

Record Class Complex

All Implemented Interfaces:
ComplexInterface

public record Complex(double real, double imaginary) extends Record implements ComplexInterface
Implementation of the ComplexInterface interface
Since:
March 2025
Version:
1.0
Author:
Saptarshi Dey
  • Constructor Details

    • Complex

      public Complex(double real, double imaginary)
      Creates an instance of a Complex record class.
      Parameters:
      real - the value for the real record component
      imaginary - the value for the imaginary record component
  • Method Details

    • add

      public Complex add(Complex other)
      Specified by:
      add in interface ComplexInterface
      Parameters:
      other - Complex number that needs to be added to the current Complex object
      Returns:
      Sum of 2 Complex numbers
    • subtract

      public Complex subtract(Complex other)
      Specified by:
      subtract in interface ComplexInterface
      Parameters:
      other - Complex number that needs to be subtracted to the current Complex object
      Returns:
      Difference between 2 Complex numbers
    • multiply

      public Complex multiply(Complex other)
      Specified by:
      multiply in interface ComplexInterface
      Parameters:
      other - Complex number that needs to be multiplied to the current Complex object
      Returns:
      Dot product of 2 Complex numbers
    • divide

      public Complex divide(Complex other)
      Specified by:
      divide in interface ComplexInterface
      Parameters:
      other - Complex number by which the current Complex object needs to be divided
      Returns:
      Quotient after division of 2 Complex numbers
    • mod

      public double mod()
      Specified by:
      mod in interface ComplexInterface
      Returns:
      Distance from the radius of the Complex number in an Euclidean complex plane
    • arg

      public double arg()
      Specified by:
      arg in interface ComplexInterface
      Returns:
      Argument of the Complex number
    • conjugate

      public Complex conjugate()
      Specified by:
      conjugate in interface ComplexInterface
      Returns:
      Conjugate of the Complex number
    • pow

      public Complex pow(double power)
      Specified by:
      pow in interface ComplexInterface
      Returns:
      Complex number raised to a real power
    • pow

      public Complex pow(Complex power)
      Specified by:
      pow in interface ComplexInterface
      Returns:
      Complex number raised to a Complex power
    • reciprocal

      public Complex reciprocal()
      Specified by:
      reciprocal in interface ComplexInterface
      Returns:
      Reciprocal of the Complex number
    • exp

      public Complex exp()
      Specified by:
      exp in interface ComplexInterface
      Returns:
      Exponent raised to the power of the Complex number
    • sin

      public Complex sin()
      Specified by:
      sin in interface ComplexInterface
      Returns:
      Sine of the Complex number
    • cos

      public Complex cos()
      Specified by:
      cos in interface ComplexInterface
      Returns:
      Cosine of the Complex number
    • log

      public Complex log(double base)
      Specified by:
      log in interface ComplexInterface
      Parameters:
      base - Base in which the Log will be computed
      Returns:
      Log of the Complex number
    • multiply

      public Complex multiply(double number)
      Specified by:
      multiply in interface ComplexInterface
      Parameters:
      number - Scalar multiplicand
      Returns:
      Scalar product of a number and a Complex number
    • toString

      public String toString(int precision)
      Parameters:
      precision - Precision of fractional part of the real and imaginary values
      Returns:
      String representation of the Complex number
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • real

      public double real()
      Returns the value of the real record component.
      Returns:
      the value of the real record component
    • imaginary

      public double imaginary()
      Returns the value of the imaginary record component.
      Returns:
      the value of the imaginary record component