You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Bruno P. Kinoshita (JIRA)" <ji...@apache.org> on 2017/04/23 01:24:04 UTC
[jira] [Commented] (NUMBERS-22) Method reciprocal() in Complex for
complex numbers with parts very close to 0.0
[ https://issues.apache.org/jira/browse/NUMBERS-22?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15980204#comment-15980204 ]
Bruno P. Kinoshita commented on NUMBERS-22:
-------------------------------------------
Adding same comment I sent to MATH-1414 as I believe it may be helpful here in NUMBERS too (also linked the ticket in JIRA).
{quote}
Trying to make sure I understand the issue in the code.
Using -2.44242319E-315 as input, here's the result in Python with NumPy.
{noformat}
>>> import numpy as np
>>> complex0 = -2.44242319e-315
>>> complex1 = np.reciprocal(complex0)
>>> complex1
-inf
>>> np.imag(complex1)
array(0.0)
{noformat}
Here's the output with GNU Octave:
{noformat}
>> complex0 = -2.44242319E-315
complex0 = -2.4424e-315
>> complex1 = 1./complex0
complex1 = -Inf
>> imag(complex1)
ans = 0
{noformat}
And in our case, as [~gjahanagirova] pointed, we get the following with the latest code from git/master:
{noformat}
Complex complex0 = new Complex((-2.44242319E-315));
Complex complex1 = complex0.reciprocal();
System.out.println(complex1.getReal());
System.out.println(complex1.getImaginary());
# Output will be:
# -Infinity
# NaN
{noformat}
For the reciprocal value, for the three libraries the real value is -Infinity. NumPy and Octave seem to agree that the imaginary part of the reciprocal is 0.0. But [math] says it is NaN.
>the value of complex1.getImaginary() will be NaN, instead of complex1 being equal to INF.
Are we sure the imaginary part of the reciprocal value must be INF, instead of 0.0 as in the other libraries?
{quote}
> Method reciprocal() in Complex for complex numbers with parts very close to 0.0
> -------------------------------------------------------------------------------
>
> Key: NUMBERS-22
> URL: https://issues.apache.org/jira/browse/NUMBERS-22
> Project: Commons Numbers
> Issue Type: Improvement
> Reporter: Gunel Jahangirova
> Priority: Minor
>
> I have been redirected here from the issue repository of Apache Commons Math, as the Complex class will likely be deprecated in favour of its equivalent in "Commons Numbers".
> In class Complex method reciprocal() returns INF only if the real and imaginary parts are exactly equal to 0.0. In the cases when real and imaginary parts are double numbers very close to 0.0, it does not hold. For example, if we run this code
> {code}
> Complex complex0 = new Complex((-2.44242319E-315));
> Complex complex1 = complex0.reciprocal();
> {code}
> the value of complex1.getReal() will be -Infinity and the value of complex1.getImaginary() will be NaN, instead of complex1 being equal to INF.
> The suggested solutions after the discussion are either checking the equality to ZERO with some tolerance or to detect if one of the real or imaginary parts is going to be infinite or NaN and then return the proper result.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)