Issue2160

classification
Title: cmath.polar gives incorrect result
Type: behaviour Severity: normal
Components: Library Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: tkohn, zyasoft
Priority: normal Keywords:

Created on 2014-06-03.09:50:52 by tkohn, last changed 2015-01-14.17:10:25 by zyasoft.

Messages
msg8596 (view) Author: Tobias Kohn (tkohn) Date: 2014-06-03.09:50:51
The function cmath.polar(x) returns a tuple (r, phi) where r should be the absolute value of x: r = abs(x). For instance, "polar(3+4j)" should return (5.0, 0.927) but Jython 2.7's value is (7.0, 0.927) instead.

This could be fixed by changing the way "r" is computed inside the "polar"-function in "cmath.java" to:

    public static PyTuple polar(PyObject in) {
        PyComplex z = complexFromPyObject(in);
        double phi = Math.atan2(z.imag, z.real);
        double r = Math.sqrt(z.real*z.real + z.imag*z.imag);  // <- Changed
        return new PyTuple(new PyFloat(r), new PyFloat(phi));
    }
msg8680 (view) Author: Jim Baker (zyasoft) Date: 2014-06-18.19:32:40
Target beta 4, should be straightforward per the patch posted
msg9064 (view) Author: Jim Baker (zyasoft) Date: 2014-10-01.19:14:40
This is tested by test_cmath, once we unskip. Thanks again for the patch - it solves a lot of failures in that test. (Unfortunately the test is too opaque in terms of how it's constructed, so I just got to it now as I picked it apart.)

Will be in trunk shortly.
msg9336 (view) Author: Jim Baker (zyasoft) Date: 2015-01-07.07:34:50
Fixed in a recent commit - there's been a lot of recent attention on complex math
History
Date User Action Args
2015-01-14 17:10:25zyasoftsetstatus: pending -> closed
2015-01-07 07:34:50zyasoftsetstatus: open -> pending
resolution: accepted -> fixed
messages: + msg9336
2014-10-01 19:14:40zyasoftsetpriority: normal
messages: + msg9064
2014-06-18 19:32:40zyasoftsetresolution: accepted
messages: + msg8680
nosy: + zyasoft
2014-06-03 09:50:52tkohncreate