[Python-3000] r60376 - in python/branches/py3k: Lib/test/test_float.py Lib/test/test_long.py Objects/stringlib/formatter.h
Nick Coghlan
ncoghlan at gmail.com
Mon Jan 28 07:06:33 CET 2008
Aahz wrote:
> On Mon, Jan 28, 2008, Nick Coghlan wrote:
>> I think this checkin goes too far in removing support for the floating
>> point formatting codes from integers. Guido objected to %d working on
>> floats last year, but expected %f and friends to continue to work on
>> integers [1]. This makes sense when you consider that there is no data
>> loss in displaying an integer as a floating point number, while there is
>> a definite potential for data loss when going the other way.
>
> Not true:
>
>>>> repr(float(1234567890123456789012345678901234567890123456789012345678901234567890))
> '1.2345678901234567e+69'
I remarked on that problem in the paragraph you cut out - the data loss
in your example is caused by the conversion to the builtin float type,
not by the act of displaying an integer as a floating point number. To
get lossless display of integers in scientific notation, all you need to
do is use the whole of the integer value as the mantissa (probably with
any trailing zeroes stripped, as we're talking about display here rather
than values intended for further processing).
That is, I think it should be possible to write something like the
following:
>>>format(1234567890123456789012345678901234567890123456789012345678900000000000,
'f')
'1.23456789012345678901234567890123456789012345678901234567890e+69'
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list