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

decimal.py: quantize(): excess digits with watchexp=0 #54859

Closed
skrah mannequin opened this issue Dec 8, 2010 · 10 comments
Closed

decimal.py: quantize(): excess digits with watchexp=0 #54859

skrah mannequin opened this issue Dec 8, 2010 · 10 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@skrah
Copy link
Mannequin

skrah mannequin commented Dec 8, 2010

BPO 10650
Nosy @birkenfeld, @rhettinger, @mdickinson, @skrah
Files
  • issue10650.diff
  • 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 = <Date 2012-08-30.10:39:41.959>
    created_at = <Date 2010-12-08.13:56:10.955>
    labels = ['type-bug', 'library']
    title = 'decimal.py: quantize(): excess digits with watchexp=0'
    updated_at = <Date 2014-04-30.17:16:20.728>
    user = 'https://github.com/skrah'

    bugs.python.org fields:

    activity = <Date 2014-04-30.17:16:20.728>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-08-30.10:39:41.959>
    closer = 'python-dev'
    components = ['Library (Lib)']
    creation = <Date 2010-12-08.13:56:10.955>
    creator = 'skrah'
    dependencies = []
    files = ['26996']
    hgrepos = []
    issue_num = 10650
    keywords = ['patch']
    message_count = 10.0
    messages = ['123603', '123607', '164429', '164430', '164439', '164467', '169141', '169448', '170085', '217631']
    nosy_count = 5.0
    nosy_names = ['georg.brandl', 'rhettinger', 'mark.dickinson', 'skrah', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue10650'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @skrah
    Copy link
    Mannequin Author

    skrah mannequin commented Dec 8, 2010

    I'm not sure if this is a documentation issue or a bug. If watchexp=0,
    quantize() also allows any number of digits:

    >>> x = Decimal("6885998238912213556789006667970467609814")
    >>> y = Decimal("1e2")
    >>> x.quantize(y)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.2/decimal.py", line 2488, in quantize
        'quantize result has too many digits for current context')
      File "/usr/local/lib/python3.2/decimal.py", line 3925, in _raise_error
        raise error(explanation)
    decimal.InvalidOperation: quantize result has too many digits for current context
    >>> 
    >>> x.quantize(y, watchexp=0)
    Decimal('6.8859982389122135567890066679704676098E+39')

    @skrah skrah mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 8, 2010
    @skrah
    Copy link
    Mannequin Author

    skrah mannequin commented Dec 8, 2010

    NaNs, however, are decapitated:

    >>> x = Decimal("NaN5357671565858315212612021522416387828577")
    >>> y = 0
    >>> x.quantize(y, watchexp=0)
    Decimal('NaN8315212612021522416387828577')

    @skrah
    Copy link
    Mannequin Author

    skrah mannequin commented Jun 30, 2012

    Ping. We have to decide if we need watchexp in _decimal. I've left it
    out so far since all I can gather from the docs is that it somehow
    behaves like _rescale.

    Can we deprecate it and replace it by a proper rescale?

    @mdickinson
    Copy link
    Member

    I'd be happy to see watchexp deprecated. It feels like a leftover implementation artefact; its behaviour isn't properly defined anywhere, and as far as I can tell it has only a single testcase.

    @rhettinger
    Copy link
    Contributor

    Does anyone know why watchexp was put there in the first place?

    http://speleotrove.com/decimal/daops.html#refquant

    If no motivation for this can be found, I agree with Mark that it should be deprecated and removed.

    @skrah
    Copy link
    Mannequin Author

    skrah mannequin commented Jul 1, 2012

    watchexp was available in rescale() from the beginning ...

    http://svn.python.org/view/sandbox/trunk/decimal/Decimal.py?revision=40721&view=markup

    ... and rescale() was renamed to quantize() in

    http://svn.python.org/view/sandbox/trunk/decimal/Decimal.py?revision=40909&view=markup

    rescale() was once part of the specification, but had identical semantics to
    quantize(), which is not specified to allow unlimited rescaling.

    I suppose the original rescale() in the sandbox had watchexp for convenience,
    in order to avoid two separate functions.

    watchexp made it into quantize(), probably because people thought there is
    a need for unlimited rescaling. This may be true, but I'd really prefer to
    expose rescale() as the unlimited version then.

    While it's unusual to just drop an API without deprecation, I think it's OK
    in this instance: Virtually all decimal code I saw needs to be cleaned up
    anyway because it uses tons of underscore methods from decimal.py.

    The only thing that worries me is that there might be code which *really*
    needs unlimited rescaling. Such code could of course also use a temporary
    context.

    So I propose this: Deprecate watchexp and leave it in the Python version for
    one release. The C version won't have watchexp from the start. After all,
    PEP-399 allows accelerator modules to implement a subset of the functionality
    of the Python version -- sometimes PEPs are a wonderful thing :).

    @skrah
    Copy link
    Mannequin Author

    skrah mannequin commented Aug 25, 2012

    Here's a patch deprecating watchexp.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 30, 2012

    New changeset 7db16ff9f5fd by Stefan Krah in branch 'default':
    Closes bpo-10650: Deprecate the watchexp parameter of Decimal.quantize().
    http://hg.python.org/cpython/rev/7db16ff9f5fd

    @python-dev python-dev mannequin closed this as completed Aug 30, 2012
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 9, 2012

    New changeset e4ca4edee8bd by Stefan Krah in branch 'default':
    Closes bpo-10650: Deprecate the watchexp parameter of Decimal.quantize().
    http://hg.python.org/cpython/rev/e4ca4edee8bd

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 30, 2014

    New changeset c2f827af02a2 by Stefan Krah in branch 'default':
    Issue bpo-10650: Remove the non-standard 'watchexp' parameter from the
    http://hg.python.org/cpython/rev/c2f827af02a2

    @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 type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants