>>> 
>>> 
>> Applicability (and name) is not straightforward, other than where it is
>> used internally.  I'd keep those "private".
>> 
>> For the API, perhaps a more general
>> ---CUT---
>> public Complex multiplyImaginary(double im) {
>>     return ofCartesian(-im * imaginary, im * real);
>> }
>> ---CUT---
>> ?
> 
> That is slated to be added for NUMBERS-139 [1].
> 
> I put in the extra add and subtract functions for ISO C99 Annex G.5.2. I have 
> not done the multiplication and divisions from Annex G.5.1 yet. I will do 
> those soon.
> 
> However unlike add/subtract I do not think that there is an issue with 
> maintaining or negating the sign of 0.0 if multiplied by 1 or -1 rather than 
> by leaving it as it or just inverting the sign. So perhaps the optimisation 
> multiplyI() is redundant, i.e:
> 
> 1 * -0.0 = -0.0
> -1 * -0.0 = 0.0
> 1 * 0.0 = 0.0
> -1 * 0.0 = -0.0
> 
> I go through the edge cases when I write the tests.

I’ve added multiplyImaginary and divideImaginary.

For all zero and non-zero data the multiplyImaginary(+/-1) produces the correct 
result for multiply by i or -i.

If the complex is non zero you can achieve the same result using 
multiply(Complex) with Complex.I and either (0, -1) or (-0.0, -1) as the 
representation of -I.

Unfortunately when the complex has zero components multiplication by a complex 
representation for I does not always work. So this justifies the inclusion of 
the multiplyImaginary(double) method. It is just not possible to do this 
without it.

There are 5 cases in the current ComplexTest where there are differences 
between the real valued methods and the complex valued methods:

divideImaginary(0.0)
divideImaginary(-0.0)
multiply(-0.0)
multiplyImaginary(0.0)
multiplyImaginary(-0.0)

All on non-zero complex numbers.

I have not yet added tests for zero-valued complex numbers. I expect to find 
more differences.

I have added a general statement to each method that the values of the 
resulting complex may have sign differences in the result compared to the 
Complex argument equivalent method if the input complex has zero parts or the 
argument is zero. I think this should be clarified a bit more on what cases the 
differences will occur.

Alex


> 
> 
> [1] 
> https://issues.apache.org/jira/projects/NUMBERS/issues/NUMBERS-139?filter=allopenissues
>  
> <https://issues.apache.org/jira/projects/NUMBERS/issues/NUMBERS-139?filter=allopenissues>
> 
>> 
>> Gilles
>> 
>>> These two operations appear a lot in the formulas for the trigonomic 
>>> functions.
>>> 
>>> They essentially just swap the real and imaginary parts and update the sign 
>>> appropriately.
>>> 
>>> Alex
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
>> For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to