Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'float': 0.05; '21,': 0.07; 'bits': 0.07; 'correct.': 0.07; 'correct,': 0.09; 'integer,': 0.09; 'sep': 0.09; 'next?': 0.16; 'wrote:': 0.17; 'integer': 0.17; 'tests': 0.18; 'equivalent': 0.20; 'followed': 0.20; 'bit': 0.21; 'implicit': 0.22; 'cheers,': 0.23; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'am,': 0.27; 'question': 0.27; 'message- id:@mail.gmail.com': 0.27; "d'aprano": 0.29; 'represented': 0.29; 'steven': 0.29; 'becomes': 0.30; 'fri,': 0.30; 'point': 0.31; 'right?': 0.33; 'to:addr:python-list': 0.33; 'equal': 0.33; 'received:google.com': 0.34; 'largest': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'subject:-': 0.40; 'header:Received:5': 0.40; 'between': 0.63; '53.': 0.84; 'gap': 0.84; 'inclusive': 0.84 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; bh=EigVnxTfxlDCIc671vbfbdxz/gMvPkce4k1+AqrXQr8=; b=ur1/zVtmc+35MgFOIFPwy4LTadV8L35MuAnGgEJ8+IRQVi6BCwcEhuE9qSA7GWzmHP RR/j+HREwU2qFVVh4NhF6sh0a8bPgsQTr9z6ussjUQUt38XGvZ/obAyfQuuL9SvF3V9r aJLS5wCjVlKCy4VA3vehbGH1CPW8jqLw8GdxreEvEcXqHorzc5Umm+1KaKHjvL6brqJi gzGBwJIMD5+VStWWls+6RkTaNrPg+oFzn27+ARhyLIQDAmWoISS2dWtGKiflbBaPhz1K zBpoBRzjoF3VlRRuKe7XZg2A7877wJclWlFahms/wwZIXoZQvsiojxTvcaD2TdjAB+E7 CeDg== MIME-Version: 1.0 In-Reply-To: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Fri, 21 Sep 2012 12:13:09 -0600 Subject: Re: Exact integer-valued floats To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348251221 news.xs4all.nl 6921 [2001:888:2000:d::a6]:37015 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29661 On Fri, Sep 21, 2012 at 11:29 AM, Steven D'Aprano wrote: > The question is, what is the largest integer number N such that every > whole number between -N and N inclusive can be represented as a float? > > If my tests are correct, that value is 9007199254740992.0 = 2**53. > > Have I got this right? Is there a way to work out the gap between one > float and the next? That looks mathematically correct. The "gap" between floats is the equivalent of a difference of 1 bit in the significand. For a floating point number represented as (sign * c * 2 ** q), where c is an integer, the gap between floats is equal to 2 ** q. There are 53 bits of precision in a double-precision float (technically an implicit 1 followed by 52 bits), so q becomes greater than 0 at 2 ** 53. Cheers, Ian