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


Groups > comp.lang.python > #56597

Re: I am never going to complain about Python again

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'mrab': 0.05; 'subject:Python': 0.06; '(except': 0.07; 'binary': 0.07; 'column': 0.07; 'error:': 0.07; '"if': 0.09; '*is*': 0.09; '[1,': 0.09; 'appropriate.': 0.09; 'mixed': 0.09; 'operand': 0.09; 'python': 0.11; '"notes"': 0.16; 'consequence,': 0.16; 'footnote': 0.16; 'operands': 0.16; 'other,': 0.16; 'rule.': 0.16; 'typeerror:': 0.16; 'types,': 0.16; 'wider': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; 'integer': 0.24; 'test.': 0.24; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; '[2]': 0.30; 'message-id:@mail.gmail.com': 0.30; '"",': 0.31; '>>>>': 0.31; 'apparently': 0.31; 'mod': 0.31; 'operations.': 0.31; 'table,': 0.31; 'file': 0.32; 'text': 0.33; '(most': 0.33; 'guess': 0.33; "can't": 0.35; 'convert': 0.35; 'equal': 0.35; 'operations': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'referred': 0.60; 'numbers': 0.61; 'real': 0.63; 'different': 0.65; 'charset:windows-1252': 0.65; 'between': 0.67; 'click': 0.77; 'mistakenly': 0.91; '2013': 0.98
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:content-transfer-encoding; bh=zsX10w2zEs7XuCTpDzIpFFEvQtdxuaLw0cdkNJZCXN4=; b=zVtpRAnnwAlgEGurJ00iNZE/yOgc79X8l1Emrv0Y6Qob5sR1k29QtC/RBEAnj/CWOe Q8d1Q4EuNFxBA8ZdBvs/yDV6hy2pKJ31D+Bh+AaJRgaNNp1Ey+kRce9UNs1cMy5AkCZP q0uFOya2H9MTGJckG087TN3RJyjDL3BhwCX5r+tNuUtG6DTsYaEG8ZcL2zOierYqBobj S9L3xEDEL/TxA1W8Edeu3kkekGMQ5NkGuQAtvhLFGwQQruVrzvQJ15Ia0y9MZU90de+t tQnWRpy3Dzbg8LMi6JsoqpkVWxsc53Du1O51MhH0bjsspJKvmY99aRqVU1GjNyhf8nAb 3nyg==
X-Received by 10.68.101.225 with SMTP id fj1mr15729673pbb.8.1381430179236; Thu, 10 Oct 2013 11:36:19 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <bbo7j0Fbp3qU1@mid.individual.net>
References <52562ee3$0$2931$c3e8da3$76491128@news.astraweb.com> <roy-582B40.09094210102013@news.panix.com> <bbo0omFa53vU1@mid.individual.net> <l36ipg$kjt$1@dont-email.me> <mailman.951.1381421409.18130.python-list@python.org> <bbo7j0Fbp3qU1@mid.individual.net>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 10 Oct 2013 12:35:38 -0600
Subject Re: I am never going to complain about Python again
To Python <python-list@python.org>
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding quoted-printable
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.955.1381430188.18130.python-list@python.org> (permalink)
Lines 63
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1381430188 news.xs4all.nl 15863 [2001:888:2000:d::a6]:56285
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:56597

Show key headers only | View raw


On Thu, Oct 10, 2013 at 11:48 AM, Neil Cerutti <neilc@norwich.edu> wrote:
> On 2013-10-10, MRAB <python@mrabarnett.plus.com> wrote:
>> On 10/10/2013 16:57, Rotwang wrote:
>>> On 10/10/2013 16:51, Neil Cerutti wrote:
>>>> [...]
>>>>
>>>> Mixed arithmetic always promotes to the wider type (except in
>>>> the case of complex numbers (Ha!)).
>>>>
>>>> r == c is equivalent to r == abs(c), which returns the magintude
>>>> of the complex number.
>>>
>>> What?
>>>
>>>   >>> -1 == -1 + 0j
>>> True
>>>   >>> -1 == abs(-1 + 0j)
>>> False
>>>   >>> 1 == 0 + 1j
>>> False
>>>   >>> 1 == abs(0 + 1j)
>>> True
>>>
>> Indeed.
>>
>> If r is real (float) and c is complex:
>>
>>      r == c means r == c.real and c.imag == 0.0
>
> Woah. I thought I was going by what the docs say:
>
>   Python fully supports mixed arithmetic: when a binary
>   arithmetic operator has operands of different numeric types,
>   the operand with the “narrower” type is widened to that of the
>   other, where integer is narrower than floating point, which is
>   narrower than complex. Comparisons between numbers of mixed
>   type use the same rule. [2] The constructors int(), float(),
>   and complex() can be used to produce numbers of a specific
>   type.
>
> [...]
>
>   [2] Not for complex numbers. Instead convert to floats using
>      abs() if appropriate.
>
> I guess the "if appropriate" part eluded my eye. When *is* it
> appropriate? Apparently not during an equal test.

If you click on the footnote, it takes you to:

[2]As a consequence, the list [1, 2] is considered equal to [1.0,
2.0], and similarly for tuples.

The text that you have mistakenly identified as the footnote is
actually part of the key to the "Notes" column of the numeric
operations table, where it is referred to by the "x % y" and
"divmod(x, y)" operations.  Specifically, it warns of this error:

>>> 3j % 2j
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't mod complex numbers.

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


Thread

I am never going to complain about Python again Steven D'Aprano <steve@pearwood.info> - 2013-10-10 04:36 +0000
  Re: I am never going to complain about Python again Chris Angelico <rosuav@gmail.com> - 2013-10-10 15:50 +1100
  Re: I am never going to complain about Python again Chris Rebert <clp2@rebertia.com> - 2013-10-09 22:26 -0700
  Re: I am never going to complain about Python again Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-10 06:39 +0100
  Re: I am never going to complain about Python again Christian Gollwitzer <auriocus@gmx.de> - 2013-10-10 08:41 +0200
  Re: I am never going to complain about Python again "Frank Millman" <frank@chagford.com> - 2013-10-10 10:23 +0200
  Re: I am never going to complain about Python again MRAB <python@mrabarnett.plus.com> - 2013-10-10 12:10 +0100
  Re: I am never going to complain about Python again Tim Chase <python.list@tim.thechases.com> - 2013-10-10 06:43 -0500
  Re: I am never going to complain about Python again "Frank Millman" <frank@chagford.com> - 2013-10-10 13:44 +0200
  Re: I am never going to complain about Python again Roy Smith <roy@panix.com> - 2013-10-10 09:09 -0400
    Re: I am never going to complain about Python again Neil Cerutti <neilc@norwich.edu> - 2013-10-10 15:51 +0000
      Re: I am never going to complain about Python again Rotwang <sg552@hotmail.co.uk> - 2013-10-10 16:57 +0100
        Re: I am never going to complain about Python again MRAB <python@mrabarnett.plus.com> - 2013-10-10 17:10 +0100
          Re: I am never going to complain about Python again Neil Cerutti <neilc@norwich.edu> - 2013-10-10 17:48 +0000
            Re: I am never going to complain about Python again Ian Kelly <ian.g.kelly@gmail.com> - 2013-10-10 12:35 -0600
              Re: I am never going to complain about Python again Neil Cerutti <neilc@norwich.edu> - 2013-10-10 18:49 +0000
            Re: I am never going to complain about Python again Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-10-10 20:47 +0100
              Re: I am never going to complain about Python again Neil Cerutti <neilc@norwich.edu> - 2013-10-10 19:54 +0000
            Re: I am never going to complain about Python again Cameron Simpson <cs@zip.com.au> - 2013-10-11 08:52 +1100
            Re: I am never going to complain about Python again Roy Smith <roy@panix.com> - 2013-10-10 20:07 -0400
              Is this the room for an argument? John Ladasky <john_ladasky@sbcglobal.net> - 2013-10-10 21:26 -0700
                Re: Is this the room for an argument? Roy Smith <roy@panix.com> - 2013-10-11 09:49 -0400
            Re: I am never going to complain about Python again Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 02:23 +0000
              Re: I am never going to complain about Python again Neil Cerutti <neilc@norwich.edu> - 2013-10-11 12:31 +0000
    Re: I am never going to complain about Python again Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-10-10 20:09 -0400
    Re: I am never going to complain about Python again Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 02:08 +0000
      Re: I am never going to complain about Python again Joshua Landau <joshua@landau.ws> - 2013-10-11 09:17 +0100
        Re: I am never going to complain about Python again Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-11 09:11 +0000
          Re: I am never going to complain about Python again Chris Angelico <rosuav@gmail.com> - 2013-10-11 20:52 +1100
          Re: I am never going to complain about Python again Joshua Landau <joshua@landau.ws> - 2013-10-11 17:56 +0100

csiph-web