[issue1678380] 0.0 and -0.0 identified, with surprising results
Mark Dickinson dicki...@gmail.com added the comment: Applied (along with a corresponding fix for the complex type) in revisions r76575 through r76578. -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1678380 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1678380] 0.0 and -0.0 identified, with surprising results
Mancausoft b...@mancausoft.org added the comment: This bug is still present on arm. Python 2.6.3 cs-e9302# cat ../prova.py import math print math.atan2(0., -0.) print (math.copysign(4., -0.), -4.0) print math.atan2(0., -0.) print (math.copysign(4., -0.), -4.0) print math.atan2(0., -0.) cs-e9302# cat ../prova1.py import math print (math.copysign(4., -0.), -4.0) print math.atan2(0., -0.) print (math.copysign(4., -0.), -4.0) print math.atan2(0., -0.) cs-e9302# ./python ../prova1.py (-4.0, -4.0) -3.14159265359 (-4.0, -4.0) -3.14159265359 cs-e9302# ./python ../prova.py 0.0 (4.0, -4.0) 0.0 (4.0, -4.0) 0.0 from math import atan2 x = -0. y = 0. print atan2(y, -1.) 3.14159265359 exec(from math import atan2; x = -0.; y = 0.; print atan2(y, -1.)) -3.14159265359 x = -0.; atan2(0., -1) -3.1415926535897931 x = 0.; atan2(0., -1) 3.1415926535897931 == FAIL: testAtan2 (__main__.MathTests) -- Traceback (most recent call last): File Lib/test/test_math.py, line 131, in testAtan2 self.ftest('atan2(0., -0.)', math.atan2(0., -0.), math.pi) File Lib/test/test_math.py, line 57, in ftest (name, value, expected)) AssertionError: atan2(0., -0.) returned 0.0, expected 3.1415926535897931 == FAIL: testCopysign (__main__.MathTests) -- Traceback (most recent call last): File Lib/test/test_math.py, line 806, in testCopysign self.assertEqual(math.copysign(4., -0.), -4.0) AssertionError: 4.0 != -4.0 -- -- nosy: +mancausoft ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1678380 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1678380] 0.0 and -0.0 identified, with surprising results
Mark Dickinson dicki...@gmail.com added the comment: Mancausoft: is this little-endian, OABI? If so, then I think I know what the problem is: the disambiguation code in compile.c looks at the first and last bytes of the double to distinguish 0.0 and -0.0; for mixed-endian (aka little-endian, swapped words) doubles this will fail. The solution is to use copysign instead. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1678380 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1678380] 0.0 and -0.0 identified, with surprising results
Mancausoft b...@mancausoft.org added the comment: Mark Dickinson rep...@bugs.python.org scrisse: Mancausoft: is this little-endian, OABI? Mixed endian If so, then I think I know what the problem is: the disambiguation code in compile.c looks at the first and last bytes of the double to distinguish 0.0 and -0.0; for mixed-endian (aka little-endian, swapped words) doubles this will fail. The solution is to use copysign instead. I try: *p==0 p[sizeof(double)-1]==0 p[(sizeof(double)-1)/2]==0; and now the test_math result is: Ran 39 tests in 21.323s OK It's a safe patch? Mancausoft -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1678380 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1678380] 0.0 and -0.0 identified, with surprising results
Mark Dickinson dicki...@gmail.com added the comment: I try: *p==0 p[sizeof(double)-1]==0 p[(sizeof(double)-1)/2]==0; Sure, that should work. It would seem cleaner and safer to use copysign, though: that way, things will still work when some other byte layout comes along, or when some version of Python starts using 128-bit IEEE 754 doubles instead of 64-bit, or ... Reopening: I've been meaning to fix these checks to use copysign for a while now, anyway. -- priority: high - normal resolution: accepted - stage: - needs patch status: closed - open type: - behavior versions: +Python 2.6, Python 2.7, Python 3.1, Python 3.2 -Python 2.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1678380 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1678380] 0.0 and -0.0 identified, with surprising results
Mark Dickinson dicki...@gmail.com added the comment: Here's a patch for floats. Mancausoft, could you give this a try and let me know whether it fixes the issue? The same fix would also need to be applied for complex numbers. -- Added file: http://bugs.python.org/file15193/issue1678380.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1678380 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1678380] 0.0 and -0.0 identified, with surprising results
Mancausoft b...@mancausoft.org added the comment: Mark Dickinson rep...@bugs.python.org scrisse: Mark Dickinson dicki...@gmail.com added the comment: Here's a patch for floats. Mancausoft, could you give this a try and let me know whether it fixes the issue? it works. test_math Ran 39 tests in 23.561s OK test_float Ran 19 tests in 275.241s OK Mancausoft -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1678380 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1678380] 0.0 and -0.0 identified, with surprising results
Mark Dickinson dicki...@gmail.com added the comment: Thanks for testing! I'll apply the fix once the 2.6 branch is unfrozen. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1678380 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1678380] 0.0 and -0.0 identified, with surprising results
Mark Dickinson added the comment: Bug identifying 0j and -0j fixed for Python 2.6 in revision 60483. Martin, can this be backported to 2.5.2? I'll assume not, unless I hear otherwise from you. -- status: open - pending _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1678380 _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1678380] 0.0 and -0.0 identified, with surprising results
Changes by Georg Brandl: -- assignee: aleax - marketdickinson _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1678380 _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1678380] 0.0 and -0.0 identified, with surprising results
Mark Dickinson added the comment: This was fixed in the trunk in revision 57284. I've backported the fix to Python 2.5.2 in revision 60183. Leaving this open because there's still a problem for complex numbers, though I guess this is less likely to bite people: Python 2.6a0 (trunk:60158M, Jan 21 2008, 16:21:41) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type help, copyright, credits or license for more information. 0j 0j -0j -0j [0j, -0j] [0j, 0j] _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1678380 _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1678380] 0.0 and -0.0 identified, with surprising results
Mark Dickinson added the comment: Here's a patch, against the trunk, that imitates Alex's fix for the complex case. -- keywords: +patch Added file: http://bugs.python.org/file9255/plus_minus_0j.patch _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1678380 _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1678380] 0.0 and -0.0 identified, with surprising results
Christian Heimes added the comment: It's fixed in 2.6 but still broken in 2.5. -- nosy: +tiran versions: +Python 2.5 _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1678380 _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com