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


Groups > comp.lang.python > #29661

Re: Exact integer-valued floats

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 <ian.g.kelly@gmail.com>
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 <ian.g.kelly@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1027.1348251221.27098.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Fri, Sep 21, 2012 at 11:29 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> 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

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


Thread

Exact integer-valued floats Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-21 17:29 +0000
  Re: Exact integer-valued floats Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-21 12:13 -0600
  Re: Exact integer-valued floats Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-09-21 22:47 +0300
  Re: Exact integer-valued floats Nobody <nobody@nowhere.com> - 2012-09-21 20:59 +0100
  Re: Exact integer-valued floats Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-21 16:26 -0400
    Re: Exact integer-valued floats Hans Mulder <hansmu@xs4all.nl> - 2012-09-21 23:04 +0200
      Re: Exact integer-valued floats Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-21 20:54 -0400
  Re: Exact integer-valued floats Alister <alister.ware@ntlworld.com> - 2012-09-21 21:14 +0000
  Re: Exact integer-valued floats Paul Rubin <no.email@nospam.invalid> - 2012-09-21 15:23 -0700
    Re: Exact integer-valued floats Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-22 01:36 +0000
      Re: Exact integer-valued floats Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-22 01:01 -0400
        Re: Exact integer-valued floats Tim Roberts <timr@probo.com> - 2012-09-22 14:05 -0700
          Re: Exact integer-valued floats Dave Angel <d@davea.name> - 2012-09-22 19:06 -0400
            Re: Exact integer-valued floats Hans Mulder <hansmu@xs4all.nl> - 2012-09-23 09:45 +0200
          Re: Exact integer-valued floats wrw@mac.com - 2012-09-24 11:29 -0400
    Re: Exact integer-valued floats Nobody <nobody@nowhere.com> - 2012-09-22 11:19 +0100

csiph-web