Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Exact integer-valued floats
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Nobody  
View profile  
 More options Sep 21 2012, 3:59 pm
Newsgroups: comp.lang.python
From: Nobody <nob...@nowhere.com>
Date: Fri, 21 Sep 2012 20:59:16 +0100
Local: Fri, Sep 21 2012 3:59 pm
Subject: Re: Exact integer-valued floats

On Fri, 21 Sep 2012 17:29:13 +0000, 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?

CPython's "float" type uses C's "double". For a system where C's "double"
is IEEE-754 double precision, N=2**53 is the correct answer.

An IEEE-754 double precision value consists of a 53-bit integer whose
first bit is a "1", multiplied or divided by a power of two.

        http://en.wikipedia.org/wiki/IEEE_754-1985

The largest 53-bit integer is 2**53-1. 2**53 can be represented as
2**52 * 2**1. 2**53+1 cannot be represented in this form. 2**53+2 can be
represented as (2**52+1) * 2**1.

For values x where 2**52 <= x < 2**53, the the interval between
representable values (aka Unit in the Last Place or ULP) is 1.0.
For 2**51 <= x < 2**52, the ULP is 0.5.
For 2**53 <= x < 2**54, the ULP is 2.0.
And so on.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.