[ 
https://issues.apache.org/jira/browse/MATH-306?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12769675#action_12769675
 ] 

Joerg Huber commented on MATH-306:
----------------------------------

Yes, it looks like a twofold check for an already solved problem. By splitting 
the code up for the two cases
1. Math.abs(c) < Math.abs(d) 
2. the other way around
the denominator of q is always non-zero, which would habe been a problem and 
may have been the reason to apply those extra checks.

The special cases c = 0 and d = 0 lead always to q = 0, in the respective code 
parts. 
Which is no problem, because there is no division by q. 
Effective code, if the extra checks are omitted.

Thank you Phil, I encourage the code cleanup you proposed.

> Method 'divide' in class 'Complex' uses a false formula for a special case 
> resulting in erroneous division by zero.
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: MATH-306
>                 URL: https://issues.apache.org/jira/browse/MATH-306
>             Project: Commons Math
>          Issue Type: Bug
>         Environment: all
>            Reporter: Joerg Huber
>
> The formula that 'divide' wants to implement is
> ( a + bi )  /  ( c + di )  =  ( ac + bd + ( bc - ad ) i )  /  ( c^2 + d^2 )
> as correctly written in the description.
> When c == 0.0 this leads to the special case
> ( a + bi )  /  di  = ( b / d ) - ( a / d ) i
> But the corresponding code is:
> if (c == 0.0) {
>     return createComplex(imaginary/d, -real/c);
> }
> The bug is the last division -real/c, which should obviously be -real/d.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to