Skip to content

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

Closed

Description

@JD-Veiga
mannequin
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']

    Activity

    1. JD-Veiga commented on Jul 3, 2020

      JD-Veigamannequin
      MannequinAuthor

      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.

    2. added
      docsDocumentation in the Doc dir
      type-featureA feature request or enhancement
      on Jul 3, 2020
    3. tim-one commented on Jul 4, 2020

      @tim-one
      Member

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

    4. JD-Veiga commented on Jul 4, 2020

      JD-Veigamannequin
      MannequinAuthor

      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).

    5. mdickinson commented on Jul 4, 2020

      @mdickinson
      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.

    6. skrah commented on Jul 4, 2020

      skrahmannequin
      Mannequin

      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.

    7. mdickinson commented on Jul 7, 2020

      @mdickinson
      Member

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

    8. skrah commented on Jul 19, 2020

      skrahmannequin
      Mannequin

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

    9. miss-islington commented on Jul 19, 2020

      @miss-islington
      Contributor

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

    10. miss-islington commented on Jul 19, 2020

      @miss-islington
      Contributor

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

    11. skrah commented on Aug 15, 2020

      skrahmannequin
      Mannequin

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

    12. transferred this issue fromon Apr 10, 2022
    13. furkanonder commented on May 10, 2023

      @furkanonder
      Contributor

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

    14. mdickinson commented on May 10, 2023

      @mdickinson
      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

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of life3.8 (EOL)end of life3.9 (EOL)end of lifedocsDocumentation in the Doc dirtype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions