Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83387
| References | (1 earlier) <mailman.17472.1420727095.18130.python-list@python.org> <87zj9te3tz.fsf@elektro.pacujo.net> <qotk30xjpib.fsf@ruuvi.it.helsinki.fi> <mailman.17477.1420729115.18130.python-list@python.org> <54af32f4$0$12990$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| Date | 2015-01-09 13:07 +1100 |
| Subject | Re: where in Nan defined |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.17493.1420769224.18130.python-list@python.org> (permalink) |
On Fri, Jan 9, 2015 at 12:46 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Chris Angelico wrote:
>
>> On Fri, Jan 9, 2015 at 1:50 AM, Jussi Piitulainen
>> <jpiitula@ling.helsinki.fi> wrote:
>>> >>> 0*1e400
>>> nan
>>
>> Nice, that's shorter than mine.
>
> I'm not entirely sure, but I suspect that 0*1e400 may not be quite as
> portable as your inf-inf. By the rules of IEEE-754 arithmetic, inf-inf has
> to return a NAN, but if your floats have sufficient precision available to
> represent 1e400, 0*1e400 might return 0.
>
> The fallback rule I use when float('nan') fails is
>
> INF = 1e3000 # Hopefully, this should overflow to INF.
> NAN = INF-INF # And this hopefully will give a NaN.
The first question is "will 1eN overflow to inf?". I'm fairly sure
Python guarantees that an unrepresentable float constant will be
treated as infinity, so all you have to do is crank up the exponent
any time you suspect it'll be representable. The second is "will 0*inf
result in nan?", and I would expect that to be as reliable as INF-INF.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
where in Nan defined maurog <qualsivoglia@dovetipare.nz> - 2015-01-08 14:15 +0000
Re: where in Nan defined Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-08 07:24 -0700
Re: where in Nan defined Marko Rauhamaa <marko@pacujo.net> - 2015-01-08 16:37 +0200
Re: where in Nan defined Chris Angelico <rosuav@gmail.com> - 2015-01-09 01:45 +1100
Re: where in Nan defined Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-01-08 16:55 +0200
Re: where in Nan defined Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-01-08 16:50 +0200
Re: where in Nan defined Chris Angelico <rosuav@gmail.com> - 2015-01-09 01:58 +1100
Re: where in Nan defined Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-09 12:46 +1100
Re: where in Nan defined Chris Angelico <rosuav@gmail.com> - 2015-01-09 13:07 +1100
Re: where in Nan defined Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-08 19:12 -0700
Re: where in Nan defined Chris Angelico <rosuav@gmail.com> - 2015-01-09 13:25 +1100
Re: where in Nan defined Chris Angelico <rosuav@gmail.com> - 2015-01-09 01:28 +1100
csiph-web