Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77965

Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))`

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 <rosuav@gmail.com>
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 <fd859066-7068-4a43-a9f0-0e9cc6949cf6@googlegroups.com>
References <06397cb3-8baf-4af1-8152-ff7c3f6ceb62@googlegroups.com> <mailman.14066.1410916403.18130.python-list@python.org> <fd859066-7068-4a43-a9f0-0e9cc6949cf6@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 <rosuav@gmail.com>
Cc "python-list@python.org" <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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14076.1410966617.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Thu, Sep 18, 2014 at 12:55 AM, cool-RR <ram.rachum@gmail.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` cool-RR <ram.rachum@gmail.com> - 2014-09-16 14:40 -0700
  Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Terry Reedy <tjreedy@udel.edu> - 2014-09-16 21:12 -0400
    Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` cool-RR <ram.rachum@gmail.com> - 2014-09-17 07:55 -0700
      Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Chris Angelico <rosuav@gmail.com> - 2014-09-18 01:10 +1000
        Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` cool-RR <ram.rachum@gmail.com> - 2014-09-17 08:16 -0700
          Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Chris Angelico <rosuav@gmail.com> - 2014-09-18 01:29 +1000
            Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` cool-RR <ram.rachum@gmail.com> - 2014-09-17 09:33 -0700
              Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Chris Angelico <rosuav@gmail.com> - 2014-09-18 02:37 +1000
              Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-18 13:11 +1000
                Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` cool-RR <ram.rachum@gmail.com> - 2014-09-18 01:43 -0700
          Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-17 09:34 -0600
          Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Chris Angelico <rosuav@gmail.com> - 2014-09-18 01:40 +1000
            Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-18 12:50 +1000
          Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-17 10:12 -0600
          Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-17 10:30 -0600
      Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-17 12:03 -0600
      Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Chris Angelico <rosuav@gmail.com> - 2014-09-18 07:37 +1000
        Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-18 13:29 +1000
          Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Chris Angelico <rosuav@gmail.com> - 2014-09-18 13:47 +1000
      Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Terry Reedy <tjreedy@udel.edu> - 2014-09-17 19:23 -0400
      Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-18 00:51 -0600
  Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-17 09:35 -0600
  Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` wxjmfauth@gmail.com - 2014-09-17 23:22 -0700
    Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Marko Rauhamaa <marko@pacujo.net> - 2014-09-18 09:45 +0300
      Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` wxjmfauth@gmail.com - 2014-09-18 00:13 -0700
      Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-18 19:25 +1000
        Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` wxjmfauth@gmail.com - 2014-09-18 05:57 -0700
        Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Grant Edwards <invalid@invalid.invalid> - 2014-09-18 14:33 +0000
    Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` chris.barker@noaa.gov - 2014-09-18 09:35 -0700
      Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-18 11:05 -0600
      Re: Why `divmod(float('inf'), 1) == (float('nan'), float('nan'))` wxjmfauth@gmail.com - 2014-09-18 23:48 -0700

csiph-web