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


Groups > comp.lang.python > #6786

Re: float("nan") in set or as key

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.linkpendium.com!news.linkpendium.com!news.snarked.org!newsfeed.news.ucla.edu!usenet.stanford.edu!news.kjsl.com!news.alt.net!news.astraweb.com!border6.newsrouter.astraweb.com!not-for-mail
From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: float("nan") in set or as key
References <mailman.2351.1306897552.9059.python-list@python.org> <b7b526f5-c839-4b3e-8e00-eee8a19078ce@glegroupsg2000goo.googlegroups.com> <mailman.2354.1306900680.9059.python-list@python.org>
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-pubkey.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
Date Wed, 01 Jun 2011 15:18:40 +1000
Message-ID <87ei3e6sen.fsf@benfinney.id.au> (permalink)
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)
Cancel-Lock sha1:FKvz3ewMEYMr6TPFOr+ySjm+MW0=
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
Lines 42
Organization Unlimited download news at news.astraweb.com
NNTP-Posting-Host fd759b62.news.astraweb.com
X-Trace DXC=3;=GGcX\?LRJ[9olalG_WRL?0kYOcDh@ZW\:Hm@YlDbZAeC]Q<\cKkZUGD@iN[Hd?_YE8aKg9ed^Q
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6786

Show key headers only | View raw


Chris Angelico <rosuav@gmail.com> writes:

> Right. Obviously a true 'real number' representation can't be done.
> But there are multiple plausible approximations thereof (the best
> being rationals).

Sure. But most of those are not what is most commonly meant by ‘float’
type.

> Not asking for Python to be changed, just wondering why it's defined
> by what looks like an implementation detail.

Because, in the case of the ‘float’ type, the agreed-upon meaning of
that type – in Python as in just about every other language that is
well-specified – is “an IEEE float as per the IEEE 754 spec”.

A foolish consistency to the spec would be a hobgoblin for little minds.
But, given that a ‘float’ type which deviated from that spec would just
be inviting all sorts of other confusion, it's not a foolish
consistency.

> It's like defining that a 'character' is an 8-bit number using the
> ASCII system, which then becomes problematic with Unicode.

Right. That's why in Python 3 the Unicode text type is called ‘unicode’,
the IEEE float type is called ‘float’, and the byte string type is
called ‘bytes’.

It's also why the ‘str’ type in Python 2 was painful enough to need
changing: it didn't clearly stick to a specification, but tried to
straddle the worlds between one specification (a text type) and an
incompatible other specification (a bytes sequence type).

Where there is a clearly-defined widely-agreed specification for a type,
it's a good idea to stick to that specification when claiming to
implement that functionality in a type.

-- 
 \       “The man who is denied the opportunity of taking decisions of |
  `\      importance begins to regard as important the decisions he is |
_o__)                        allowed to take.” —C. Northcote Parkinson |
Ben Finney

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


Thread

Re: float("nan") in set or as key Carl Banks <pavlovevidence@gmail.com> - 2011-05-31 20:30 -0700
  Re: float("nan") in set or as key Roy Smith <roy@panix.com> - 2011-05-31 23:43 -0400
    Re: float("nan") in set or as key Grant Edwards <invalid@invalid.invalid> - 2011-06-01 14:04 +0000
  Re: float("nan") in set or as key Chris Angelico <rosuav@gmail.com> - 2011-06-01 13:57 +1000
    Re: float("nan") in set or as key Ben Finney <ben+python@benfinney.id.au> - 2011-06-01 15:18 +1000
  Re: float("nan") in set or as key Jerry Hill <malaclypse2@gmail.com> - 2011-06-01 09:44 -0400
  Re: float("nan") in set or as key Chris Angelico <rosuav@gmail.com> - 2011-06-02 02:12 +1000

csiph-web