Path: csiph.com!usenet.pasdenom.info!news.franciliens.net!fdn.fr!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'sufficient': 0.05; 'float': 0.07; 'overflow': 0.09; 'sure,': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'jan': 0.12; 'exponent': 0.16; 'fallback': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inf': 0.16; 'infinity,': 0.16; 'mine.': 0.16; 'nan': 0.16; 'portable': 0.16; 'subject:where': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'rules': 0.22; 'cc:addr:python.org': 0.22; 'fairly': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'constant': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'quite': 0.32; 'entirely': 0.33; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'shorter': 0.36; 'should': 0.36; 'represent': 0.38; 'pm,': 0.38; 'expect': 0.39; 'sure': 0.39; 'skip:u 10': 0.60; 'first': 0.61; '2015': 0.84; 'nice,': 0.84; 'to:none': 0.92 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=NAMzMNaT3DFjHyvSkndxuL1RH/6os2UBDpnSRnKk5Xk=; b=HWszia0XzMiZKcMiiKN+Gab4JM9drEal8Th3UpkHvqVLMGnffr1lH1yOEpIQ39J6D/ a/IPsQdzpZ8NbRVh6VYXbI/IEW7mvapwXuN4fw67Gr20HAe0nWGjEpX/FTRHPGsTcYsz V/vSon8eu4J+pCvySheDbb6EZ2l9krJpqpPzlWU+mwIwZPR9YrMTNCYAa2v/ajlNKKnA wJKs+NadDT0tny8o7oiWZ2trh3fjSP9igo+t/DSkIaIhpl95+e8N+6Mw0XmtLbWJrqet fhPJ8BrHpqwL5m/IkYbJXSJcyZ40Enm9rLb+S6undf7G/0Ac6yFzcjlSECmHFaHE62Ax dOCw== MIME-Version: 1.0 X-Received: by 10.42.52.200 with SMTP id k8mr11079207icg.26.1420769221928; Thu, 08 Jan 2015 18:07:01 -0800 (PST) In-Reply-To: <54af32f4$0$12990$c3e8da3$5496439d@news.astraweb.com> References: <87zj9te3tz.fsf@elektro.pacujo.net> <54af32f4$0$12990$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 9 Jan 2015 13:07:01 +1100 Subject: Re: where in Nan defined From: Chris Angelico Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1420769224 news.xs4all.nl 2873 [2001:888:2000:d::a6]:52297 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83387 On Fri, Jan 9, 2015 at 12:46 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> On Fri, Jan 9, 2015 at 1:50 AM, Jussi Piitulainen >> 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