Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failure in test_math::testSum #47671

Closed
birkenfeld opened this issue Jul 20, 2008 · 8 comments
Closed

Test failure in test_math::testSum #47671

birkenfeld opened this issue Jul 20, 2008 · 8 comments
Assignees
Labels
extension-modules C modules in the Modules dir tests Tests in the Lib/test dir

Comments

@birkenfeld
Copy link
Member

BPO 3421
Nosy @birkenfeld, @rhettinger, @mdickinson

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/mdickinson'
closed_at = <Date 2008-07-26.15:43:22.836>
created_at = <Date 2008-07-20.22:35:19.665>
labels = ['extension-modules', 'tests']
title = 'Test failure in test_math::testSum'
updated_at = <Date 2009-03-29.13:00:41.806>
user = 'https://github.com/birkenfeld'

bugs.python.org fields:

activity = <Date 2009-03-29.13:00:41.806>
actor = 'mark.dickinson'
assignee = 'mark.dickinson'
closed = True
closed_date = <Date 2008-07-26.15:43:22.836>
closer = 'georg.brandl'
components = ['Extension Modules', 'Tests']
creation = <Date 2008-07-20.22:35:19.665>
creator = 'georg.brandl'
dependencies = []
files = []
hgrepos = []
issue_num = 3421
keywords = []
message_count = 8.0
messages = ['70094', '70293', '70294', '70296', '70302', '70303', '70306', '84388']
nosy_count = 3.0
nosy_names = ['georg.brandl', 'rhettinger', 'mark.dickinson']
pr_nums = []
priority = 'normal'
resolution = 'works for me'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue3421'
versions = ['Python 3.0']

@birkenfeld
Copy link
Member Author

In Py3k, but not in trunk:

======================================================================
FAIL: testSum (test.test_math.MathTests)
----------------------------------------------------------------------

Traceback (most recent call last):
  File "/home/gbr/devel/python3k/Lib/test/test_math.py", line 769, in
testSum
    self.assertEqual(math.sum(vals), s)
OverflowError: math range error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/gbr/devel/python3k/Lib/test/test_math.py", line 772, in
testSum
    "for math.sum(%.100r)" % (i, s, vals))
AssertionError: test 13 failed: got OverflowError, expected
1.7976931348623157e+308 for math.sum([1.7976931348623157e+308,
9.979201547673598e+291])

System info: linux x86, glibc 2.8

@birkenfeld birkenfeld added extension-modules C modules in the Modules dir tests Tests in the Lib/test dir labels Jul 20, 2008
@mdickinson
Copy link
Member

Sadly, this is not the only problem with math.sum on x86 hardware right
now. I'd guess that this is another problem related to double-rounding
and the use of 80-bit floating-point registers on x86. Raymond and I
are still actively looking for ways to fix math.sum up, including the
possibility of a complete rewrite using a totally different algorithm.

With the current algorithm, behaviour at or near the boundary of the
floating-point range should really be considered undefined; so the
quick fix is to update the tests and docs to reflect this. The
particular test that causes test.math to fail would just be removed.

I am intrigued that py3k and the trunk give different results, though;
I'd very much like to know where the difference comes from.

Georg, *only if you have time*, could you please tell me what results
the linux box gives for the following two Python sums, in both py3k and
the trunk:

>>> 1e16 + 2.9999
10000000000000002.0
>>> 1.7976931348623157e+308 + 9.979201547673598e+291
1.7976931348623157e+308

(The results shown are the ones I get on OS X 10.5.4; I don't have
access to a linux box for testing at the moment.)

@mdickinson
Copy link
Member

See also bpo-2819 for ongoing discussion, and bpo-2937, which is the
likely root cause of the current difficulties with math.sum.

@birkenfeld
Copy link
Member Author

Both trunk and 3k give this:

>>> 1e16 + 2.9999
10000000000000004.0
>>> 1.7976931348623157e+308 + 9.979201547673598e+291
inf

@mdickinson
Copy link
Member

Thanks. Those are the results I'd expect on x86. So here's the puzzle:

On lines 658-9 of Lib/test/test_math.py, in revision 65248 of the py3k
branch, there's a pair of lines that looks like:

        if 1e16+2.999 != 1e16+2.9999:
            return

These lines are supposed to bail out of testSum on IEEE 754 hardware
that doesn't do correct rounding. So on your machine, I'd expect:

1e16+2.999 to evaluate to 10000000000000002.0
1e16+2.9999 to evaluate to 10000000000000004.0

so the condition in the if statement ought to be True, and the rest of
the tests should be skipped.

It looks like this bailout is working as intended in the trunk, but not
in Py3k. Any ideas why there's a difference? Is there some sort of
constant folding going on in py3k but not in the trunk?

@birkenfeld
Copy link
Member Author

Strangely, it seems to work now with 3k too -- both in a debug and
release build. I've no idea what changed, but I'll close this for now.

@rhettinger
Copy link
Contributor

The tests at floating point boundaries should probably be removed and
their behavior should be left undefined.

@mdickinson
Copy link
Member

See also bpo-5593.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir tests Tests in the Lib/test dir
Projects
None yet
Development

No branches or pull requests

3 participants