Looking for the greatest negative float value

Bengt Richter bokr at oz.net
Thu Jun 12 12:11:22 EDT 2003


On 11 Jun 2003 22:01:43 -0700, danb_83 at yahoo.com (Dan Bishop) wrote:

>mwilson at the-wire.com (Mel Wilson) wrote in message news:<Yr55+ks/KTSM089yn at the-wire.com>...
>> In article <bc7lvb$gm3$1 at news-reader12.wanadoo.fr>,
>> "Gilles Lenfant" <glenfant at NOSPAM.bigfoot.com> wrote:
>> >Hi,
>> >
>> >I need the same as...
>> >
>> >import sys
>> >negmaxint = - sys.maxint -1
>> >
>> >... but for float data
>[snip]
>> -1.7976931348623157e+308
>> 
>> and that last number seems credible.
>
>Close.  The exact value, per the IEEE 754 standard, is -(2 ** 1024 - 2
>** 972), or -1.7976931348623155e+308.  How did you get a *higher*
>magnitude?

Because UIAM the IEEE 754 standard allows 53 significant bits, not 52.
Note that your constant can be rewritten:

 >>> -(2**1024 - 2**972) == -(2**52 - 1)*2**972
 1

Yet 2**53-1 is eactly representable in a floating point double:

 >>> float(2**53-1)
 9007199254740991.0

and so of course is the single-bit 2**53

 >>> float(2**53+0)
 9007199254740992.0

but not the next number - it rounds down to 2**53

 >>> float(2**53+1)
 9007199254740992.0

starting with 2**53, the lsb is counts by 2

 >>> float(2**53+2)
 9007199254740994.0

So therefore your constant is a 52-bit number, and we can make one that has 53:

Your number:

 >>> float(-(2**52 - 1)*2**972)
 -1.7976931348623155e+308

The 53-bit number:

 >>> float(-(2**53 - 1)*2**971)
 -1.7976931348623157e+308

or like your original format:

 >>> float(-(2**1024 - 2**971))
 -1.7976931348623157e+308

Bottom line: UIAM the 972 should have been 971
(i.e., 2**971 is the lsb in that number, not 2**972).

Regards,
Bengt Richter




More information about the Python-list mailing list