Package complex
Record Class Complex
java.lang.Object
java.lang.Record
complex.Complex
- All Implemented Interfaces:
ComplexInterface
Implementation of the ComplexInterface interface
- Since:
- March 2025
- Version:
- 1.0
- Author:
- Saptarshi Dey
-
Constructor Summary
ConstructorsConstructorDescriptionComplex
(double real, double imaginary) Creates an instance of aComplex
record class. -
Method Summary
Modifier and TypeMethodDescriptiondouble
arg()
cos()
final boolean
Indicates whether some other object is "equal to" this one.exp()
final int
hashCode()
Returns a hash code value for this object.double
Returns the value of theimaginary
record component.log
(double base) double
mod()
multiply
(double number) pow
(double power) double
real()
Returns the value of thereal
record component.sin()
toString()
Returns a string representation of this record class.toString
(int precision)
-
Constructor Details
-
Complex
public Complex(double real, double imaginary) Creates an instance of aComplex
record class.- Parameters:
real
- the value for thereal
record componentimaginary
- the value for theimaginary
record component
-
-
Method Details
-
add
- Specified by:
add
in interfaceComplexInterface
- Parameters:
other
- Complex number that needs to be added to the current Complex object- Returns:
- Sum of 2 Complex numbers
-
subtract
- Specified by:
subtract
in interfaceComplexInterface
- Parameters:
other
- Complex number that needs to be subtracted to the current Complex object- Returns:
- Difference between 2 Complex numbers
-
multiply
- Specified by:
multiply
in interfaceComplexInterface
- Parameters:
other
- Complex number that needs to be multiplied to the current Complex object- Returns:
- Dot product of 2 Complex numbers
-
divide
- Specified by:
divide
in interfaceComplexInterface
- 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 interfaceComplexInterface
- Returns:
- Distance from the radius of the Complex number in an Euclidean complex plane
-
arg
public double arg()- Specified by:
arg
in interfaceComplexInterface
- Returns:
- Argument of the Complex number
-
conjugate
- Specified by:
conjugate
in interfaceComplexInterface
- Returns:
- Conjugate of the Complex number
-
pow
- Specified by:
pow
in interfaceComplexInterface
- Returns:
- Complex number raised to a real power
-
pow
- Specified by:
pow
in interfaceComplexInterface
- Returns:
- Complex number raised to a Complex power
-
reciprocal
- Specified by:
reciprocal
in interfaceComplexInterface
- Returns:
- Reciprocal of the Complex number
-
exp
- Specified by:
exp
in interfaceComplexInterface
- Returns:
- Exponent raised to the power of the Complex number
-
sin
- Specified by:
sin
in interfaceComplexInterface
- Returns:
- Sine of the Complex number
-
cos
- Specified by:
cos
in interfaceComplexInterface
- Returns:
- Cosine of the Complex number
-
log
- Specified by:
log
in interfaceComplexInterface
- Parameters:
base
- Base in which the Log will be computed- Returns:
- Log of the Complex number
-
multiply
- Specified by:
multiply
in interfaceComplexInterface
- Parameters:
number
- Scalar multiplicand- Returns:
- Scalar product of a number and a Complex number
-
toString
- Parameters:
precision
- Precision of fractional part of the real and imaginary values- Returns:
- String representation of the Complex number
-
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. -
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. -
equals
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 '=='. -
real
public double real()Returns the value of thereal
record component.- Returns:
- the value of the
real
record component
-
imaginary
public double imaginary()Returns the value of theimaginary
record component.- Returns:
- the value of the
imaginary
record component
-