You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex Herbert (Jira)" <ji...@apache.org> on 2019/12/26 15:28:00 UTC

[jira] [Resolved] (NUMBERS-139) Complex Multiplicative and Additive operators

     [ https://issues.apache.org/jira/browse/NUMBERS-139?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alex Herbert resolved NUMBERS-139.
----------------------------------
    Fix Version/s: 1.0
       Resolution: Done

All missing operators have been added to git master.

> Complex Multiplicative and Additive operators
> ---------------------------------------------
>
>                 Key: NUMBERS-139
>                 URL: https://issues.apache.org/jira/browse/NUMBERS-139
>             Project: Commons Numbers
>          Issue Type: Improvement
>          Components: complex
>    Affects Versions: 1.0
>            Reporter: Alex Herbert
>            Assignee: Alex Herbert
>            Priority: Minor
>             Fix For: 1.0
>
>
> [ISO C99|http://www.open-std.org/JTC1/SC22/WG14/www/standards] Annex G specifies the multiplicative (G.5.1) and additive operators (G.5.2) in the case where the first or second argument is a real or an imaginary number. The following methods are already implemented:
> {code:java}
> multiply(Complex)
> multiply(double)
> divide(Complex)
> divide(double)
> add(Complex)
> add(double)
> subtract(Complex)
> subtract(double)
> {code}
> Add the following methods:
> {code:java}
> multiplyImaginary(double)
> divideImaginary(double)
> addImaginary(double)
> subtractImaginary(double)
> subtractFrom(double)
> subtractFromImaginary(double)
> {code}
> The final cases are important to maintain the negation of the sign of the component not involved in the computation.
> This computation:
> {noformat}
> 1 - (a + b i) = (1 - a) - b i
> {noformat}
> Is not correct for {{b=0}} using e.g.:
> {code:java}
> new Complex(1, 0).subtract(new Complex(3, 0));
> {code}
> The result is (-2, 0) but it should be (-2, -0).
> Using the Complex involves zero subtraction for the imaginary part {{0 - 0}} but a special method would just use {{-0}} and negate the sign.
> Note: In ISO compliant C++ the use of a complex makes no special preservation of the sign of the negative:
> {code:c++}
> 1.0 - complex<double>(3, 0.0)                    == -2 + -0 i
> 1.0 - complex<double>(3, -0.0)                   == -2 + 0 i
> complex<double>(1, 0) - complex<double>(3, 0.0)  == -2 + 0 i
> complex<double>(1, 0) - complex<double>(3, -0.0) == -2 + 0 i
> {code}
> The first case listed above is not possible with the current API.
> The method subtractFrom(Complex) would have an identical result as using subtract(Complex) and so adds no functional value to the API and is omitted.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)