ComplexNumberPackage

Last edit February 27, 2010
ComplexNumberPackage must support the following operators:

Let z1 = x1 + y1j and z2 = x2 + y2j.

  • ==: z1 == z2 if and only if x1 = x2 and y1 = y2.

  • +: z1 + z2 = (x1 + x2) + (y1 + y2)j

  • -: z1 - z2 = (x1 - x2) + (y1 - y2)j

  • *: z1 * z2 = (x1x2 - y1y2) + (x1y2 + x2y1)j

  • /: z1 / z2 = ((x1x2 + y1y2)/(x2^2 + y2^2)) + ((x2y1 - x1y2)/(x2^2 + y2^2))j (for z2 ~= 0).

It must also handle coefficients (real and imaginary) with an arbitrary mix of the following primitive types:

  • byte: 8-bit signed 2's-complement integer
  • short: 16-bit signed 2's-complement integer
  • int: 32-bit signed 2's-complement integer
  • long: 64-bit signed 2's-complement integer
  • float: 32-bit IeeeSevenFiftyFour-1985 floating-point number
  • double: 32-bit IeeeSevenFiftyFour-1985 floating-point number

Each of the arithmetic operations must operate correctly when applied to any non-complex argument -- ie: (1.2 + 3.4j) + 5 = (6.2 + 3.4j).

Each of the arithmetic operations must, of course, be commutative, including with mixed arguments -- ie: (A + Bj) * C == C * (A + Bj) and so on.

If any of us get truly motivated, we should probably write ComplexNumberPackageUnitTest that must be passed by a putative candidate. We then contrast and compare the performance of packages that pass the unit test.
See also ComplexNumbers, ComplexNumberTest
CategoryMath