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

Documentation Decimal power 0 to the 0 is Nan (versus 0 to the 0 which is 1) #85377

Closed
JD-Veiga mannequin opened this issue Jul 3, 2020 · 12 comments
Closed

Documentation Decimal power 0 to the 0 is Nan (versus 0 to the 0 which is 1) #85377

JD-Veiga mannequin opened this issue Jul 3, 2020 · 12 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@JD-Veiga
Copy link
Mannequin

JD-Veiga mannequin commented Jul 3, 2020

BPO 41205
Nosy @tim-one, @rhettinger, @facundobatista, @mdickinson, @skrah, @srinivasreddy, @miss-islington
PRs
  • bpo-41205: Document Decimal power 0 to the 0 #21386
  • [3.9] bpo-41205: Document Decimal power 0 to the 0 (GH-21386) #21547
  • [3.8] bpo-41205: Document Decimal power 0 to the 0 (GH-21386) #21548
  • 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 2020-07-03.22:51:25.441>
    labels = ['type-feature', '3.8', '3.9', '3.10', 'docs']
    title = 'Documentation Decimal power 0 to the 0 is Nan (versus 0 to the 0 which is 1)'
    updated_at = <Date 2020-08-15.20:48:36.169>
    user = 'https://bugs.python.org/JD-Veiga'

    bugs.python.org fields:

    activity = <Date 2020-08-15.20:48:36.169>
    actor = 'skrah'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2020-07-03.22:51:25.441>
    creator = 'JD-Veiga'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41205
    keywords = ['patch']
    message_count = 10.0
    messages = ['372969', '372975', '372980', '372982', '372986', '373225', '373956', '373958', '373959', '375495']
    nosy_count = 9.0
    nosy_names = ['tim.peters', 'rhettinger', 'facundobatista', 'mark.dickinson', 'skrah', 'docs@python', 'thatiparthy', 'miss-islington', 'JD-Veiga']
    pr_nums = ['21386', '21547', '21548']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'pending'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue41205'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @JD-Veiga
    Copy link
    Mannequin Author

    JD-Veiga mannequin commented Jul 3, 2020

    Hi,

    I would like to propose a minor addition to decimal package documentation page (https://docs.python.org/3/library/decimal.html). I think that we should add a paragraph in context.power(x, y, modulo=None) stating that Decimal(0) ** Decimal(0) returns Decimal('NaN') instead of 1 --as 0 ** 0 does-- or 1.0 --in case of 0.0 ** 0.0.

    Indeed, 0 ** 0 is NaN is mentioned as example of operations raising InvalidOperation exceptions.

    However, I think that this is not enough to indicate the different behaviour of decimal versus int and float numbers.

    Moreover, in the case of % and // operators, there are clear remarks on these differences (See: “There are some small differences between arithmetic on Decimal objects and arithmetic on integers and floats [...]” in the page).

    Thank you and sorry for the inconvenience.

    @JD-Veiga JD-Veiga mannequin added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Jul 3, 2020
    @JD-Veiga JD-Veiga mannequin assigned docspython Jul 3, 2020
    @JD-Veiga JD-Veiga mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Jul 3, 2020
    @JD-Veiga JD-Veiga mannequin assigned docspython Jul 3, 2020
    @JD-Veiga JD-Veiga mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Jul 3, 2020
    @tim-one
    Copy link
    Member

    tim-one commented Jul 4, 2020

    Huh! I thought everyone in Standards World gave up by now, and agreed 0**0 should be 1.

    @JD-Veiga
    Copy link
    Mannequin Author

    JD-Veiga mannequin commented Jul 4, 2020

    Well, it is the way that it has been defined in decimal package and in the document that inspired this package (IBM's General Decimal Arithmetic Specification, The General Decimal Arithmetic Specification: http://speleotrove.com/decimal/decarith.html).

    @mdickinson
    Copy link
    Member

    I agree that the result is surprising and should be noted in the docs; we shouldn't expect all the decimal users to be familiar with the specification. Some of the other differences with float arithmetic are noted (e.g., the behaviour of // and %), but apparently not this one. We do document the behaviour of these corner cases for math.pow.

    The part that I find really odd is that the specification says that Decimal("inf")**Decimal(0) is 1. Treating one of 00 and inf0 as undefined but not the other seems inconsistent to me. We'd probably want to note the behaviour of inf**0 in the docs, too. (I tried to argue with Mike Cowlishaw about this, but I lost.)

    I'm not sure whether just noting this in the "power" documentation is enough: it's not clear to me that users using the ** operator would think to check the docs for the "power" method.

    The other weirdly non-IEEE 754 behaviour (again, mandated by the standard) that bugs me from time to time is that the unary - and + operators will never give negative zero: Decimal("-0.0") and -Decimal("0.0") are not the same thing. That one's probably worth noting, too.

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Jul 4, 2020

    Agreed, and it's even slightly worse with the ROUND_FLOOR special case:

    >>> c.rounding = ROUND_FLOOR
    >>> +Decimal("-0")
    Decimal('-0')
    >>> 

    That's why there are three slightly different methods for applying the
    context:

    1. context.create_decimal() ==> special case for NaN payloads.

    2. context.apply() (private method) ==> no special cases at all.

    3. Decimal.plus() ==> ROUND_FLOOR special case.

    @mdickinson
    Copy link
    Member

    @JD-Veiga: would you be willing to work on a PR?

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Jul 19, 2020

    New changeset 10e4664 by Srinivas Reddy Thatiparthy (శ్రీనివాస్ రెడ్డి తాటిపర్తి) in branch 'master':
    bpo-41205: Document Decimal power 0 to the 0 (GH-21386)
    10e4664

    @miss-islington
    Copy link
    Contributor

    New changeset 8831162 by Miss Islington (bot) in branch '3.9':
    bpo-41205: Document Decimal power 0 to the 0 (GH-21386)
    8831162

    @miss-islington
    Copy link
    Contributor

    New changeset dac8a3a by Miss Islington (bot) in branch '3.8':
    bpo-41205: Document Decimal power 0 to the 0 (GH-21386)
    dac8a3a

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Aug 15, 2020

    Mark, do you think that we should document the other oddity as well
    or should we close this?

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @furkanonder
    Copy link
    Sponsor Contributor

    @skrah Issue seems to be solved. We can close the issue.

    @mdickinson
    Copy link
    Member

    Closing. It doesn't seem worth documenting the inf**0 oddity unless someone yells.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants