Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.05; 'true,': 0.05; 'element': 0.07; 'exception.': 0.09; 'subject:Why': 0.09; '*only*': 0.16; '1),': 0.16; '42,': 0.16; 'all).': 0.16; 'division.': 0.16; 'inf': 0.16; 'nan': 0.16; 'reason.': 0.16; 'tuple.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'thu,': 0.19; '>>>': 0.22; 'focusing': 0.24; 'possibly': 0.26; 'second': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'raise': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; '>>>>': 0.31; 'mod': 0.31; 'sep': 0.31; "we're": 0.32; '(i.e.': 0.33; 'could': 0.34; "can't": 0.35; 'agree': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'maintained': 0.36; 'returning': 0.36; "didn't": 0.36; 'possible': 0.36; 'should': 0.36; 'example,': 0.37; 'wrong': 0.37; 'too': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'ian': 0.60; 'talking': 0.65; 'actually,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=0BZFMlhS0NivuSBEqStEWnni51YpLA5np7QpOTHlfPI=; b=qUffmvbqRKRe2DaTB+VxMUISRD6PqoizHmssBJL/KD3YVrGNCE6/lvJio3jHNK07JA 76UKtPHP1OI/DLG3Yb86SNP4VTQ5FflCWcRvjo2DZE/6F2PxChNZtvxj4scPRue7b3SQ p5Rk4o0Q38qpEjEE12m0DnYLE/kaUhR/NV+T3m9QONoJXn9ciOPGU8MWFoAhWGnLVzdk REIScWNELe9Aw2VBGoWUlE4nU2+mm9Ii+gvlHnYe/KyhzO2I2bwsLfksZ1C2M5Mz37qu HrJ0y3+vV5QwNXSVsGJXKSFXzlRbsiFqy0SVE73FS3mb1RHZnFdGmmk6HpzG24rlpS9s 2l2w== X-Received: by 10.180.211.36 with SMTP id mz4mr42088861wic.39.1410971463864; Wed, 17 Sep 2014 09:31:03 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <151e45ce-444d-441c-b59b-67e2aee3882b@googlegroups.com> From: Ian Kelly Date: Wed, 17 Sep 2014 10:30:23 -0600 Subject: Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1410971471 news.xs4all.nl 2872 [2001:888:2000:d::a6]:49607 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77977 On Wed, Sep 17, 2014 at 9:40 AM, Chris Angelico wrote: > On Thu, Sep 18, 2014 at 1:34 AM, Ian Kelly wrote: >> On Wed, Sep 17, 2014 at 9:29 AM, Chris Angelico wrote: >>> On Thu, Sep 18, 2014 at 1:16 AM, cool-RR wrote: >>>> I didn't ask for the modulo, I agree it should remain NaN. I'm talking about the floor division. >>>> >>> >>> Invariant: div*y + mod == x. >>> >>> If mod is NaN, there is no possible value for div that will make the >>> invariant true, ergo it too has to be NaN. >> >> That still doesn't make the invariant true. By this argument div could >> be 42, and the invariant would hold equally well (i.e. not at all). > > Nothing can possibly make it true, so there are only two > possibilities: return NaN, or raise an exception. Actually, I think we're focusing on the wrong element of the tuple. The fact is that there are values that can make the invariant true. For example, divmod(inf, 1) could return (inf, 0). inf * 1 + 0 = inf. (inf, 1), or (inf, ) would work equally well. The *only* reason the invariant can't be maintained is because we're committed to returning nan for the second element for some reason.