next up previous print clean
Next: Appendix C: Deconvolution in Up: Appendix A: Java enhancements Previous: Indexing operator

Primitive complex number type:

I advocate to include a complex number type in the Java API. Complex numbers are important in many applications in sciences, engineering, finance, and graphics. Their representation is not complex enough to warrant the overhead a class implementation incurs. Without a standard implementation, additional wrapper classes are needed to make varying implementations compatible. Additionally, since Java does not support operator overloading, such a complex number class cannot offer the concise mathematical expressions that we expect. For example, the following code would compute the root of a quadratic equation, if Java had a complex primitive type[*]:

static complex root(complex a, complex b, complex c) {
  return (-b + complex.sqrt(b*b-4*a*c))/(2*a);
}
Instead Java currently requires:
static Complex root(Complex a, Complex b, Complex c) {
  Complex b2      = Complex.multiply(b,b);
  Complex ac4     = Complex.multiply(4,Complex.multiply(a,c)); 
  Complex discrim = Complex.sqrt(Complex.subtract(b2,ac4)); 
  return Complex.divide(Complex.subtract(discrim,b)),Complex.multiply(2,a))); 
}

A complex number type would have to be accompanied by the standard unary and binary operators. The operators should allow for mixed operands such as float and complex. Operators without a complex extension, such as increment and modulus, would, of course, not exist. Furthermore, the class should be accompanied by a set of static class methods corresponding to the java.lang.Math package for the double type.


next up previous print clean
Next: Appendix C: Deconvolution in Up: Appendix A: Java enhancements Previous: Indexing operator
Stanford Exploration Project
3/8/1999