Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6985
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.mb-net.net!open-news-network.org!news.mind.de!bolzen.all.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Gregory Ewing <greg.ewing@canterbury.ac.nz> |
| Newsgroups | comp.lang.python |
| Subject | Re: float("nan") in set or as key |
| Date | Sat, 04 Jun 2011 12:14:03 +1200 |
| Lines | 67 |
| Message-ID | <94tbmeF41kU1@mid.individual.net> (permalink) |
| References | <mailman.2206.1306626083.9059.python-list@python.org> <94dkd3F7k4U1@mid.individual.net> <4de1e3e7$0$2195$742ec2ed@news.sonic.net> <4de22007$0$29996$c3e8da3$5496439d@news.astraweb.com> <pan.2011.05.29.21.19.12.375000@nowhere.com> <4de2d746$0$29996$c3e8da3$5496439d@news.astraweb.com> <pan.2011.06.01.20.40.18.453000@nowhere.com> <4de75dd5$0$29983$c3e8da3$5496439d@news.astraweb.com> <94qjvvFb02U1@mid.individual.net> <4de861ae$0$29985$c3e8da3$5496439d@news.astraweb.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net apfAmEYSOXDlNjRIHBb23gUQy1slFEefhkV+dxchQ9vnINZcFf |
| Cancel-Lock | sha1:mc47N5cxWLZBURvEBUcAgpSxPu8= |
| User-Agent | Mozilla Thunderbird 1.0.5 (Macintosh/20050711) |
| X-Accept-Language | en-us, en |
| In-Reply-To | <4de861ae$0$29985$c3e8da3$5496439d@news.astraweb.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:6985 |
Show key headers only | View raw
Steven D'Aprano wrote: > Fair point. Call it an extension of the Kronecker Delta to the reals then. That's called the Dirac delta function, and it's a bit different -- instead of a value of 1, it has an infinitely high spike of zero width at the origin, whose integral is 1. (Which means it's not strictly a function, because it's impossible for a true function on the reals to have those properties.) You don't normally use it on its own; usually it turns up as part of an integral. I find it difficult to imagine a numerical algorithm that relies on directly evaluating it. Such an algorithm would be numerically unreliable. You just wouldn't do it that way; you'd find some other way to calculate the integral that avoids evaluating the delta. > y = 2.1e12 > if abs(x - y) <= 1e-9: > # x is equal to y, within exact tolerance > ... If you expect your numbers to be on the order of 1e12, then 1e-9 is obviously not a sensible choice of tolerance. You don't just pull tolerances out of thin air, you justify them based on knowledge of the problem at hand. > In practice, either the function needs some sort of "how to decide > equality" parameter, If it's general purpose library code, then yes, that's exactly what it needs. > or you use exact floating point equality and leave it > up to the caller to make sure the arguments are correctly rounded Not really a good idea. Trying to deal with this kind of thing by rounding is fraught with difficulties and pitfalls. It can only work when you're not really using floats as approximations of reals, but as some set of discrete values, in which case it's probably safer to use appropriately-scaled integers. > - from William Kahan, and the C99 standard: hypot(INF, x) is always INF > regardless of the value of x, hence hypot(INF, NAN) returns INF. > > - since pow(x, 0) is always 1 regardless of the value of x, pow(NAN, 0) > is also 1. These are different from your kronecker(), because the result *never* depends on the value of x, whether it's NaN or not. But kronecker() clearly does depend on the value of x sometimes. The reasoning appears to be based on the idea that NaN means "some value, we just don't know what it is". Accepting that interpretation, the argument doesn't apply to kronecker(). You can't say that the NaN in kronecker(NaN, 42) doesn't matter, because if you don't know what value it represents, you can't be sure that it *isn't* meant to be 42. > Another standard example where NANs get thrown away is the max and min > functions. The latest revision of IEEE-754 (2008) allows for max and min > to ignore NANs. Do they provide a justification for that? I'm having trouble seeing how it makes sense. -- Greg
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
float("nan") in set or as key MRAB <python@mrabarnett.plus.com> - 2011-05-29 00:41 +0100
Re: float("nan") in set or as key Erik Max Francis <max@alcyone.com> - 2011-05-28 17:16 -0700
Re: float("nan") in set or as key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 00:26 +0000
Re: float("nan") in set or as key Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-05-29 13:04 +1200
Re: float("nan") in set or as key John Nagle <nagle@animats.com> - 2011-05-28 23:12 -0700
Re: float("nan") in set or as key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 10:29 +0000
Re: float("nan") in set or as key Nobody <nobody@nowhere.com> - 2011-05-29 22:19 +0100
Re: float("nan") in set or as key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 23:31 +0000
Re: float("nan") in set or as key Nobody <nobody@nowhere.com> - 2011-06-01 21:41 +0100
Re: float("nan") in set or as key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-02 09:54 +0000
Re: float("nan") in set or as key Grant Edwards <invalid@invalid.invalid> - 2011-06-02 13:05 +0000
Re: float("nan") in set or as key Robert Kern <robert.kern@gmail.com> - 2011-06-02 12:04 -0500
Re: float("nan") in set or as key Nobody <nobody@nowhere.com> - 2011-06-02 21:47 +0100
Re: float("nan") in set or as key Grant Edwards <invalid@invalid.invalid> - 2011-06-03 14:52 +0000
Re: float("nan") in set or as key Chris Torek <nospam@torek.net> - 2011-06-03 17:52 +0000
Re: float("nan") in set or as key Grant Edwards <invalid@invalid.invalid> - 2011-06-06 13:54 +0000
Re: float("nan") in set or as key Nobody <nobody@nowhere.com> - 2011-06-04 00:29 +0100
Re: float("nan") in set or as key Chris Angelico <rosuav@gmail.com> - 2011-06-04 09:51 +1000
Re: float("nan") in set or as key rusi <rustompmody@gmail.com> - 2011-06-04 00:52 -0700
Re: float("nan") in set or as key Nobody <nobody@nowhere.com> - 2011-06-04 20:29 +0100
Re: float("nan") in set or as key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-05 07:21 +0000
Re: float("nan") in set or as key Nobody <nobody@nowhere.com> - 2011-06-05 19:15 +0100
Re: float("nan") in set or as key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-06 00:55 +0000
Re: float("nan") in set or as key Nobody <nobody@nowhere.com> - 2011-06-06 23:14 +0100
Re: float("nan") in set or as key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-06 23:44 +0000
Re: float("nan") in set or as key Chris Angelico <rosuav@gmail.com> - 2011-06-07 11:00 +1000
Re: float("nan") in set or as key Grant Edwards <invalid@invalid.invalid> - 2011-06-06 14:03 +0000
Re: float("nan") in set or as key Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-06-03 11:17 +1200
Re: float("nan") in set or as key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-03 04:23 +0000
Re: float("nan") in set or as key Chris Angelico <rosuav@gmail.com> - 2011-06-03 14:35 +1000
Re: float("nan") in set or as key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-03 05:59 +0000
Re: float("nan") in set or as key Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-06-04 12:14 +1200
Re: float("nan") in set or as key Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-04 02:21 +0000
Re: float("nan") in set or as key Erik Max Francis <max@alcyone.com> - 2011-06-05 00:27 -0700
Re: float("nan") in set or as key Grant Edwards <invalid@invalid.invalid> - 2011-06-01 21:01 +0000
Re: float("nan") in set or as key Chris Torek <nospam@torek.net> - 2011-05-30 00:02 +0000
Re: float("nan") in set or as key Raymond Hettinger <python@rcn.com> - 2011-05-29 21:49 -0700
csiph-web