Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!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.049 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'modulo': 0.09; 'raises': 0.09; 'subject:Why': 0.09; 'cc:addr:python-list': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inf': 0.16; 'infinity': 0.16; 'infinity,': 0.16; 'integer.': 0.16; 'nan': 0.16; 'tends': 0.16; 'zero,': 0.16; 'so.': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'thanks.': 0.20; 'cc:addr:python.org': 0.22; 'mathematical': 0.24; '(or': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'reaches': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'posting': 0.31; 'division': 0.31; 'sep': 0.31; 'style': 0.33; 'something': 0.35; 'definition': 0.35; 'good.': 0.35; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'google': 0.35; 'there': 0.35; 'really': 0.36; 'next': 0.36; 'possible': 0.36; 'positive': 0.37; 'question,': 0.38; 'that,': 0.38; 'little': 0.38; 'anything': 0.39; 'sure': 0.39; 'how': 0.40; 'blank': 0.60; 'new': 0.61; 'simply': 0.61; 'first': 0.61; 'back': 0.62; 'real': 0.63; 'answer.': 0.68; 'anything.': 0.68; 'limit': 0.70; 'increase': 0.74; 'etc,': 0.84; 'divided': 0.91; 'why?': 0.91; 'to:none': 0.92; 'serious': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=XymNjUGWwINovRLRdJbm+MOaN4kMg4J5BT5/30xjXlg=; b=Xehpycz0Bu/7DKQLWIzlzJPTl19kwtw1BMvvcrHQ4XFGtOvg0GcGuKs1CuBphIbO4A Vtem4feD2vI+8IzmrK0aylQW6r5649MMabK66DSd05b/fSWVcmuSmkqxdL+ffd7HgCXB d/9zdUD8QVjXJmI9PEv7Q/haWaC0pA+F7eIjJcDZGvOPdnny7vdUHvSb0cLvnYDGKojC 4zhtoMgKhjX8Afpi0Gmj3fxfpLCG7UNEEmblnRv/ATZ9/NOCM7PQpfoJRXiXJehmPiBe y8McPByIg8YfYH392YXxDGtIY0C3wzINRf6xkCUgvtYGYYS/msbg0rMk9TXCLtiZ1eWi fSyA== MIME-Version: 1.0 X-Received: by 10.42.92.129 with SMTP id t1mr5578389icm.59.1410966614632; Wed, 17 Sep 2014 08:10:14 -0700 (PDT) In-Reply-To: References: <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> Date: Thu, 18 Sep 2014 01:10:14 +1000 Subject: Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` From: Chris Angelico Cc: "python-list@python.org" 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1410966617 news.xs4all.nl 2879 [2001:888:2000:d::a6]:41238 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77965 On Thu, Sep 18, 2014 at 12:55 AM, cool-RR wrote: > Terry, that doesn't really answer the question "why", it just pushes it back to the documentation. Is there a real answer why? Why return NaN when Inf would make mathematical sense? > To answer that, we have to first look at what it means to do operations on Inf. The definition of "Infinity + 1" is the limit of "x + 1" as x goes toward positive infinity - which is positive infinity. Same with infinity-1, infinity/1, infinity*1, etc, etc, etc. So far, so good. But as x tends toward positive infinity, the value of "x // 1" (or simply of floor(x)) doesn't simply increase tidily. It goes up in little jumps, every time x reaches a new integer. And while it's conceivable to define that infinity divided by anything is infinity, and infinity modulo anything is zero, that raises serious issues of primality and such; I'm not sure that that would really help anything. So there's no possible value for floor division of infinity, ergo the result is NaN. So. There you have an answer. Now, for your next question, can you please use something better than Google Groups, or at least learn how to use an interleaved posting style and trim out all the excess blank lines? Thanks. ChrisA