GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Document the meaning of the number in OverflowError · Issue #91290 · python/cpython

Document the meaning of the number in OverflowError #91290

New issue
Copy link
New issue
Copy link
Open
Open
Document the meaning of the number in OverflowError#91290
Copy link
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc dirtype-featureA feature request or enhancementA feature request or enhancement

Description

@stevendaprano
stevendaprano
opened on Mar 26, 2022
Issue body actions
BPO 47134
Nosy @stevendaprano, @eryksun

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 = None
closed_at = None
created_at = <Date 2022-03-26.22:10:10.212>
labels = ['3.7', '3.8', '3.9', '3.10', '3.11', 'type-feature', 'docs']
title = 'Document the meaning of the number in OverflowError'
updated_at = <Date 2022-03-26.22:46:01.129>
user = 'https://github.com/stevendaprano'

bugs.python.org fields:

activity = <Date 2022-03-26.22:46:01.129>
actor = 'eryksun'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation']
creation = <Date 2022-03-26.22:10:10.212>
creator = 'steven.daprano'
dependencies = []
files = []
hgrepos = []
issue_num = 47134
keywords = []
message_count = 2.0
messages = ['416093', '416096']
nosy_count = 3.0
nosy_names = ['steven.daprano', 'docs@python', 'eryksun']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue47134'
versions = ['Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']

Activity

  1. stevendaprano commented on Mar 26, 2022

    @stevendaprano
    stevendaprano
    on Mar 26, 2022
    MemberAuthor
    More actions

    OverflowError sometimes (but not always) includes some sort of numeric code:

    >>> 1e+300 ** 2
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OverflowError: (34, 'Numerical result out of range')

    but the meaning of the 34 is not documented:

    https://docs.python.org/3/library/exceptions.html#OverflowError

    help(OverflowError) is no more insightful, saying only:

        __init__(self, /, *args, **kwargs)
            Initialize self.  See help(type(self)) for accurate signature.

    Other OverflowError exceptions do not include the numeric code:

    >>> math.exp(10000)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OverflowError: math range error

    Is it an error code from C? Something to do with the number of digits of precision? An easter-egg to do with The Count Of Monte Cristo?

    Reacted by Václav Brožík
  2. stevendaprano
    added
    3.7 (EOL)end of lifeend of life
    3.8 (EOL)end of lifeend of life
    3.9 (EOL)end of lifeend of life
    3.10 (EOL)end of lifeend of life
    3.11only security fixesonly security fixes
    on Mar 26, 2022
  3. stevendaprano
    assigned
    docspython
    on Mar 26, 2022
  4. stevendaprano
    added
    3.9 (EOL)end of lifeend of life
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    3.10 (EOL)end of lifeend of life
    type-featureA feature request or enhancementA feature request or enhancement
    3.11only security fixesonly security fixes
    on Mar 26, 2022
  5. stevendaprano
    assigned
    docspython
    on Mar 26, 2022
  6. stevendaprano
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    type-featureA feature request or enhancementA feature request or enhancement
    on Mar 26, 2022
  7. eryksun commented on Mar 26, 2022

    @eryksun
    eryksun
    on Mar 26, 2022
    Contributor
    More actions

    The error code for 1e+300 ** 2 is ERANGE, from calling libm pow(). Since pow() returns a double, there's no way to indicate an error in the return value. Instead, C errno is set to 0 beforehand and checked for a non-zero error value after the call. If the error code isn't ERANGE, then float.pow() raises ValueError instead of OverflowError. Here's the relevant snippet from float_pow() in Objects/floatobject.c:

    /* Now iv and iw are finite, iw is nonzero, and iv is
     * positive and not equal to 1.0.  We finally allow
     * the platform pow to step in and do the rest.
     */
    errno = 0;
    ix = pow(iv, iw);
    _Py_ADJUST_ERANGE1(ix);
    if (negate_result)
        ix = -ix;
    
        if (errno != 0) {
            /* We don't expect any errno value other than ERANGE, but
             * the range of libm bugs appears unbounded.
             */
            PyErr_SetFromErrno(errno == ERANGE ? PyExc_OverflowError :
                                 PyExc_ValueError);
            return NULL;
        }
        return PyFloat_FromDouble(ix);

    Here's a direct example using ctypes:

        import ctypes
        import errno
    
        libm = ctypes.CDLL('libm.so.6', use_errno=True)
        libm.pow.argtypes = (ctypes.c_double, ctypes.c_double)
        libm.pow.restype = ctypes.c_double
        >>> errno.ERANGE
        34
        >>> ctypes.set_errno(0)
        0
        >>> libm.pow(1e300, 2)
        inf
        >>> ctypes.get_errno() == errno.ERANGE
        True
    Reacted by Stanley
  8. ezio-melotti
    transferred this issue fromon Apr 10, 2022
  9. slateny commented on Sep 9, 2022

    @slateny
    slateny
    on Sep 9, 2022
    Contributor
    More actions

    For improvements, maybe the errno page can directly list the constant equivalents, and then the page could be referenced in the exceptions page?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc dirtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.