[Python-Dev] str with base

Steve Holden steve at holdenweb.com
Wed Jan 18 09:41:09 CET 2006


Adam Olsen wrote:
> On 1/17/06, Bob Ippolito <bob at redivi.com> wrote:
> 
>>On Jan 17, 2006, at 3:38 PM, Adam Olsen wrote:
>>
>>
>>>I dream of a day when str(3.25, base=2) == '11.01'.  That is the
>>>number a float really represents.  It would be so much easier to
>>>understand why floats behave the way they do if it were possible to
>>>print them in binary.
>>
>>Actually if you wanted something that closely represents what a
>>floating point number is then you would want to see this::
>>
>>        >>> str(3.25, base=2)
>>        '1.101e1'
>>        >>> str(0.25, base=2)
>>        '1.0e-10'
>>
>>Printing the bits without an exponent is nearly as misleading as
>>printing them in decimal.
> 
> 
> I disagree.  The exponent is involved in rounding to fit in compact
> storage but once that is complete the value can be represented exactly
> without it.
> 
Albeit with excessively long representations for the larger values one 
sometimes sees represented in float form.

Personally I wouldn't even be interested in seeing 
1.3407807929942597e+154 written in fixed point form *in decimal*, let 
alone in binary where the representation, though unambiguous, would have 
over 500 bits, most of them zeros.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/



More information about the Python-Dev mailing list