Issue1853

classification
Title: Complex does not maintain negative for -0.0
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: zyasoft Nosy List: fwierzbicki, pjenvey, zyasoft
Priority: low Keywords:

Created on 2012-03-16.19:20:49 by fwierzbicki, last changed 2015-01-07.07:58:43 by zyasoft.

Messages
msg6804 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2012-03-16.19:20:49
On Ubuntu Linux
[frank jython]$ ./dist/bin/jython
Jython 2.7a0+ (default:f24c04861f32+, Mar 16 2012, 12:06:43) 
[OpenJDK 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_23
Type "help", "copyright", "credits" or "license" for more information.
>>> complex(-0.0, -0.0)
0j
>>>
msg6807 (view) Author: Philip Jenvey (pjenvey) Date: 2012-03-17.00:12:11
Maintaining the sign actually changed in 2.6
msg6808 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2012-03-17.18:52:45
Thanks for the clarification pjenvey - I set the "Version" flag to 2.7a1 accordingly.
msg8731 (view) Author: Jim Baker (zyasoft) Date: 2014-06-19.06:38:41
Still an issue, if slightly different:

$ python
Python 2.7.5 (default, Mar  9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> complex(-0.0, -0.0)
(-0-0j)

$ jython27
Jython 2.7b3+ (default:7516d3820146+, Jun 18 2014, 22:11:17)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_21
Type "help", "copyright", "credits" or "license" for more information.
>>> complex(-0.0, -0.0)
(-0+0j)
msg9054 (view) Author: Jim Baker (zyasoft) Date: 2014-09-27.05:49:31
Easy to fix this specific issue, although there are other issues to consider in test_cmath:

diff -r 9fef5da411e5 src/org/python/core/PyComplex.java
--- a/src/org/python/core/PyComplex.java	Fri Sep 26 11:43:55 2014 -0600
+++ b/src/org/python/core/PyComplex.java	Fri Sep 26 23:41:54 2014 -0600
@@ -113,7 +113,12 @@
         }

         complexReal.real -= complexImag.imag;
-        complexReal.imag += complexImag.real;
+        if (complexReal.imag == 0.0) {
+            // necessary if complexImag is -0.0, given that adding 0.0 + -0.0 is 0.0
+            complexReal.imag = complexImag.real;
+        } else {
+            complexReal.imag += complexImag.real;
+        }
         if (new_.for_type != subtype) {
             complexReal = new PyComplexDerived(subtype, complexReal.real, complexReal.imag);
         }

Similar care has to be done with cmath.acos, etc. I compared CPython with Wolfram Alpha (they are comparable), so it looks like we should follow what CPython has done in those cases.
msg9177 (view) Author: Jim Baker (zyasoft) Date: 2014-10-28.22:58:20
I fixed the easy issues in test_cmath. Most of the remaining ones - the transcendental functions in cmath and their precision - will likely require revisiting with Apache Commons Math, but stripped down, since it's > 10M.

Marking low accordingly.
msg9340 (view) Author: Jim Baker (zyasoft) Date: 2015-01-07.07:58:42
Remaining problems are being tracked in #2237, this bug has long been fixed
History
Date User Action Args
2015-01-07 07:58:43zyasoftsetstatus: open -> closed
resolution: fixed
messages: + msg9340
2014-10-28 22:58:20zyasoftsetpriority: high -> low
messages: + msg9177
2014-10-06 03:32:01zyasoftsetpriority: normal -> high
2014-09-30 19:12:51santa4ntsettype: behaviour
components: + Core
2014-09-27 05:49:32zyasoftsetassignee: fwierzbicki -> zyasoft
messages: + msg9054
2014-06-19 06:38:41zyasoftsetnosy: + zyasoft
messages: + msg8731
2013-02-20 00:39:39fwierzbickisetpriority: normal
assignee: fwierzbicki
versions: + Jython 2.7, - 2.7a1
2012-03-17 18:52:45fwierzbickisetmessages: + msg6808
versions: + 2.7a1
2012-03-17 00:12:11pjenveysetnosy: + pjenvey
messages: + msg6807
2012-03-16 19:20:50fwierzbickicreate