This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test.cmath fails on OS/X with gcc-4.8 in non-debug build
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: mark.dickinson, python-dev, rhettinger
Priority: normal Keywords:

Created on 2013-07-20 08:22 by rhettinger, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (8)
msg193402 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2013-07-20 08:22
======================================================================
FAIL: test_specific_values (__main__.CMathTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/raymondhettinger/cpython/Lib/test/test_cmath.py", line 382, in test_specific_values
    msg=error_message)
  File "/Users/raymondhettinger/cpython/Lib/test/test_cmath.py", line 128, in rAssertAlmostEqual
    'got {!r}'.format(a, b))
AssertionError: rect1017: rect(complex(0.0, -0.0))
Expected: complex(0.0, -0.0)
Received: complex(0.0, 0.0)
Received value insufficiently close to expected value.
msg193410 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-07-20 15:47
Hmm.  Looks similar to issue #15477, but that one was fixed (we added a local workaround and reported the OS bug to Apple).  And it was with clang rather than gcc.

Raymond:  from the title, can I assume that you don't see this failure on a debug build?  That would tend to point to a compiler optimization bug.
msg193412 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-07-20 16:45
I can't reproduce this here on OS 10.6 (I don't have access to anything later), but I think I can guess what's happening:  I suspect that gcc 4.8 is optimizing the pair of 'cos' and 'sin' calls into a single call to 'cexp'.  And then the OS X library implementation of _cexp has buggy behaviour with respect to signs of zeros (this last part is something I've witnessed before, but I forget which version of OS X it was on).

It's easy to work around, by adding a special case for zeros in cmath_rect.  It's a bit annoying to have to do so, though.
msg193413 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-20 17:00
New changeset ce771c2d0220 by Mark Dickinson in branch '3.3':
Issue #18513: Add workaround for OS X 10.8 cexp bug that leads to wrong cmath.rect(0.0,-0.0) results.
http://hg.python.org/cpython/rev/ce771c2d0220

New changeset ae769deb45b2 by Mark Dickinson in branch 'default':
Issue #18513: Add workaround for OS X 10.8 cexp bug that leads to wrong cmath.rect(0.0,-0.0) results.
http://hg.python.org/cpython/rev/ae769deb45b2
msg193414 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-07-20 17:01
Should be fixed now.
msg193418 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-20 17:59
New changeset 91374660355a by Raymond Hettinger in branch '2.7':
Issue #18513: Add workaround for OS X 10.8 cexp bug that leads to wrong cmath.rect(0.0,-0.0) results.
http://hg.python.org/cpython/rev/91374660355a
msg193419 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2013-07-20 18:01
Thanks Mark.  test_cmath passed now.  I've also applied this to Python2.7.
msg193420 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-07-20 18:12
Thanks, Raymond.

Postscript:  I had a feeling of deja vu about this, and I've just been searching through old emails.  It turns out I filed an OS X bug (#6466807  ) for this exact issue back in 2008;  cexp was broken in 10.5, fixed in 10.6, and clearly is now broken again in 10.8.  I've added a note to that Apple bug report, for what it's worth.
History
Date User Action Args
2022-04-11 14:57:48adminsetgithub: 62713
2013-07-20 18:12:38mark.dickinsonsetmessages: + msg193420
2013-07-20 18:01:35rhettingersetmessages: + msg193419
2013-07-20 17:59:51python-devsetmessages: + msg193418
2013-07-20 17:01:07mark.dickinsonsetstatus: open -> closed
versions: + Python 3.3
messages: + msg193414

resolution: fixed
stage: resolved
2013-07-20 17:00:27python-devsetnosy: + python-dev
messages: + msg193413
2013-07-20 16:45:33mark.dickinsonsetmessages: + msg193412
2013-07-20 15:47:01mark.dickinsonsetmessages: + msg193410
2013-07-20 08:22:09rhettingercreate