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


Groups > comp.lang.python > #29685

Re: Exact integer-valued floats

From Alister <alister.ware@ntlworld.com>
Subject Re: Exact integer-valued floats
Newsgroups comp.lang.python
References <505ca3e9$0$29981$c3e8da3$5496439d@news.astraweb.com>
Message-ID <VM47s.294148$Up5.270868@fx06.am4> (permalink)
Organization virginmedia.com
Date 2012-09-21 21:14 +0000

Show all headers | View raw


On Fri, 21 Sep 2012 17:29:13 +0000, Steven D'Aprano wrote:

> Python floats can represent exact integer values (e.g. 42.0), but above
> a certain value (see below), not all integers can be represented. For
> example:
> 
> py> 1e16 == 1e16 + 1  # no such float as 10000000000000001.0 True py>
> 1e16 + 3 == 1e16 + 4  # or 10000000000000003.0 True
> 
> So some integers are missing from the floats. For large enough values,
> the gap between floats is rather large, and many numbers are missing:
> 
> py> 1e200 + 1e10 == 1e200 True
> 
> The same applies for large enough negative values.
> 
> 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?
> 
> (I haven't tried to exhaustively check every float because, even at one
> nanosecond per number, it will take over 200 days.)

technically this would be implementation dependant, although the other 
responses are probably accurate for most (if not all) current 
implementations :-)



-- 
Well, I'm a classic ANAL RETENTIVE!!  And I'm looking for a way to
VICARIOUSLY experience some reason to LIVE!!

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