Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Complex number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Complex number" Watch "Complex number" New topic
Author

Complex number

william brown
Greenhorn

Joined: Jul 19, 2005
Posts: 16
Hi,

Do JAVA provide complex number operation class?
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

No.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

But Google shows there are loads of third party Complex number classes. e.g. http://www.ee.ucl.ac.uk/~mflanaga/java/Complex.html
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Moving this to Java in General (Beginner) forum as it has nothing to do with GUI related stuff.


GenRocket - Experts at Building Test Data
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
No, a complex number class is not generally useful and never required, emphasis on generally and required.

When you have a specific problem domains that requires complex types you can use two variables. When that becomes too much of a burden, use a third-party class or create your own. There are certainly problems that would be a royal pain without a specific Complex class.

Apache Commons has a Complex class, for example:

http://jakarta.apache.org/commons/math/apidocs/org/apache/commons/math/complex/Complex.html
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

No, a complex number class is not generally useful and never required, emphasis on generally and required.


As an engineer I would have to disagree with you here! Maybe in your applications complex is 'not generally useful' but in my applications it is very useful. In fact it is essential!

The data type double and float are 'never required' since one could use BigDecimal but the speed an notational convenience make them essential. I would like to see a primitive type 'complex double' that would allow the standard operators */+- to be used. This would make Java much more useful to engineers and scientists.


When you have a specific problem domains that requires complex types you can use two variables. When that becomes too much of a burden, use a third-party class or create your own. There are certainly problems that would be a royal pain without a specific Complex class.


Yes you can use two variables to represent each number. That is what I have to do at the moment. It stinks. Consider mutiplyong two complex number a and b. The code without complex is

double ar = 4.2;
double ai = 2.2;
double br = 1.7;
double bi = 0.5;

double cr = ar*br-ai*ci;
double ci = ar*bi+ai*br;

but the code with complex is

complex double a = (5.2, 2.2);
complex double b = (1,7, 0,5);
complex double c = a * b;

Which is easiest to read? If you do a large number of complex 'complex' calculations then the current approach is error prone and very difficult to read.

Though a complex class makes things a bit better, since one can't use operator overloading in Java one still has to define methods like Complex.add() and Complex.mul(). Also, the fact that you have to create a Java object to represent your complex numbers makes the overhead of using the Complex class too great except in the most simple of applications.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Complex number
 
Similar Threads
My random integer generator.
Basic class design
WA #1.....word association
Add button to Mandelbrot Set
Can someone shed some light on this program