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_math: math.log(-ninf) fails to raise exception on OpenBSD #47932

Closed
djmdjm mannequin opened this issue Aug 26, 2008 · 4 comments
Closed

test_math: math.log(-ninf) fails to raise exception on OpenBSD #47932

djmdjm mannequin opened this issue Aug 26, 2008 · 4 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@djmdjm
Copy link
Mannequin

djmdjm mannequin commented Aug 26, 2008

BPO 3682
Nosy @mdickinson
Files
  • patch-Modules_mathmodule_c
  • 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-12-11.22:08:16.179>
    created_at = <Date 2008-08-26.00:03:46.248>
    labels = ['library']
    title = 'test_math: math.log(-ninf) fails to raise exception on OpenBSD'
    updated_at = <Date 2008-12-11.22:08:16.178>
    user = 'https://bugs.python.org/djmdjm'

    bugs.python.org fields:

    activity = <Date 2008-12-11.22:08:16.178>
    actor = 'mark.dickinson'
    assignee = 'mark.dickinson'
    closed = True
    closed_date = <Date 2008-12-11.22:08:16.179>
    closer = 'mark.dickinson'
    components = ['Library (Lib)']
    creation = <Date 2008-08-26.00:03:46.248>
    creator = 'djmdjm'
    dependencies = []
    files = ['11258']
    hgrepos = []
    issue_num = 3682
    keywords = []
    message_count = 4.0
    messages = ['71963', '72391', '77150', '77635']
    nosy_count = 2.0
    nosy_names = ['mark.dickinson', 'djmdjm']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue3682'
    versions = ['Python 2.6']

    @djmdjm
    Copy link
    Mannequin Author

    djmdjm mannequin commented Aug 26, 2008

    Hi,

    On OpenBSD 4.4, the test_math.py regression test fails with the following:

    Traceback (most recent call last):
      File "Lib/test/test_math.py", line 419, in testLog
        self.assertRaises(ValueError, math.log, NINF)
    AssertionError: ValueError not raised

    This is because libm's log function does not return NaN when passed
    -INFINITY. It returns -INFINITY and sets EDOM. This behaviour seems to
    be permitted by the C99 spec (ISO/IEC 9899:1999):

    7.12.1 Treatment of error conditions
    paragraph2:
    ... On a domain error, the function returns an implementation-defined
    value; if the integer expression math_errhandling & MATH_ERRNO is
    nonzero, the integer expression errno acquires the value EDOM;

    in mathmodule.c:math_1() errno seems to be deliberately ignored when the
    result is infinite. The attached patch modified math_1() to retain EDOM
    errors for infinite results.

    @djmdjm djmdjm mannequin added the stdlib Python modules in the Lib dir label Aug 26, 2008
    @mdickinson
    Copy link
    Member

    It's possible that this patch would cause breakage on other systems:
    there's a reason that errno is currently ignored, which is that it can't
    be trusted on all systems (notably Linux: on one Linux system I've used
    of three different evaluations, all of log singularity type (log(0),
    log1p(-1), atanh(1), ...), one gave errno=EDOM, one gave errno=ERANGE,
    and one didn't set errno at all).

    So I'm reluctant to mess with math_1, especially this close to a release.

    An alternative solution would be to check special cases for log directly
    within the mathmodule.c code, only passing positive nonspecial arguments
    to the system log function. This would have a much lower risk of
    causing breakage on other systems. Note that Solaris with Sun's
    compiler also has some problems with log: depending on compiler
    options, etc., log(-1.0) can give -inf instead of nan. So having Python
    deal with log special cases directly seems like a good thing to do there
    as well.

    @mdickinson
    Copy link
    Member

    Damien, if you're still there:

    Please could you try the patch "math_log.patch" attached to bpo-3167,
    and let me know whether it fixes the test failure?

    @mdickinson
    Copy link
    Member

    I've committed the bpo-3167 fix in revisions r67707 to r67710.
    I'm fairly sure that this patch should resolve this issue. (Let me know
    if it doesn't.)

    @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
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant