commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Barnhill <>
Subject Re: Proposed changes to Complex method nomenclature
Date Wed, 01 Jun 2016 19:53:59 GMT

On 31/05/16 14:12, Gilles wrote:
> Short as can be and close to math notation.
> Another possibility may be to keep long names and to add syntactic
> sugar such as
> -----
> public static double im(Complex c) {
>     return c.getImaginary();
> }
> -----

I have been looking at std::complex to get some ideas. Connected to the 
issue (coming soon in another thread) of conforming the Complex to C99.


Do you see any value in conforming to this reference? If so, this could 
mostly be accomplished by adding a few syntactic sugar methods, while 
leaving in longer-name methods that follow the commons style, to which I 
also see benefit.

These would include real, imag, abs, arg, conj .

Then a few methods are missing which are not much trouble -- log10 and 
norm are easy, but I am not familiar with proj, which is only in C11 anyway.

>> This leaves only the question of a constructor that takes polar
>> representations which I think is already well handled by the present 
>> method
>> ComplexUtils.polar2Complex, for either Complex or Complex[] .
> Shall we consider making the constructors "private" and define
> factory methods (like those currently in "ComplexUtils")?
> public static Complex createCartesian(double re,
>                                       double im) {
>     return new Complex(re, im);
> }
> public static Complex createPolar(double r,
>                                   double theta) {
>     return new Complex(r * FastMath.cos(theta),
>                        r * FastMath.sin(theta));
> }

It seems to follow the criteria for factory pattern, in that we want to 
give the user ways to create the object that are most convenient 
(cartesian or polar), uncoupled from object structure.

> And suppress the ambiguous methods "createComplex" and
> "valueOf".


> Actually I think that only one constructor should stay that
> is tied to the underlying representation (and for that reason
> it should not be "public").

> What do you think?

I figure one goal is for the Complex to not be much bigger than two 
doubles. So real and imag are probably what should be in the structure, 
with the polar values calculated, and a factory method used to construct 
complex from polar.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message