Aaron Meurer <asmeu...@gmail.com> added the comment:

I meant that format() destroys information in a decimal in general. Obviously 
if you have n digits of precision and format with m < n, then you lose 
information. 

I also can't help but feel that we're mixing up "trailing zeros" (i.e., 
precision), and "exponent" (magnitude), which should be orthogonal. I'm 
assuming that a decimal is represented internally as base*10**exponent. I'm 
also assuming that Decimal(0) sets both base and exponent to 0. It doesn't make 
sense to me that a string formatting operation that requests a certain number 
of digits of precision should change the exponent. 

I get that 0.0 is different from 0.00000, but in that case, they should print 
differently: as '0.0' and '0.00000'. It seems sly to try to maintain that 
through a format operation via the exponent, especially when format *in 
general* loses precision information for a decimal anyway (by "format" I mean 
format with a set number of digits requested). Especially since that "trick" 
only works for exactly one number, zero. If you do 
'{:+.30e}'.format(Decimal('1.0000000000000000000')) or 
'{:+.10e}'.format(Decimal('1.0000000000000000000')), no such trick is used, 
because no such trick can be used. You just lose information. 

I'm sure my mental model is off here. I'm used to sympy.Float/mpmath.mpf where 
values like 0*2**i are normalized to i = 0 (e.g. mpmath.mpf((0, 0, 20, 
0))._mpf_ gives (0, 0, 0, 0)), so this problem never comes up in the code that 
I'm used to.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31684>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to