[issue31684] Scientific formatting of decimal 0 different from float 0

2017-10-04 Thread Stefan Krah
Stefan Krah added the comment: > I'm also assuming that Decimal(0) sets both base and exponent to 0. No, 0 is really special in the IBM specification. The magnitude is kept, the precision is not. >>> Decimal("0e10") * Decimal("0e20") Decimal('0E+30') >>> Decimal("0.000e10") Decimal('0E+7')

[issue31684] Scientific formatting of decimal 0 different from float 0

2017-10-04 Thread Aaron Meurer
Aaron Meurer 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

[issue31684] Scientific formatting of decimal 0 different from float 0

2017-10-04 Thread Stefan Krah
Stefan Krah added the comment: I don't think format() destroys the information: >>> '{:+.19e}'.format(Decimal("0.0e20")) '+0.000e+34' The original magnitude was e+15, after formatting it's still e+15. -- ___ Python tracker

[issue31684] Scientific formatting of decimal 0 different from float 0

2017-10-04 Thread Aaron Meurer
Aaron Meurer added the comment: I guess I would expect that to be captured by the number of zeros printed (and obviously doing a string format operation with a set number of digits destroys that information). -- ___ Python tracker

[issue31684] Scientific formatting of decimal 0 different from float 0

2017-10-04 Thread Stefan Krah
Stefan Krah added the comment: Yes, from the point of view of decimal it's the right thing: >>> x = Decimal("1e25").quantize(Decimal("1e30")) >>> x Decimal('0E+30') >>> '{:+.19e}'.format(x) '+0.000e+49' >>> The original magnitude should be traceable (the example is not perfect

[issue31684] Scientific formatting of decimal 0 different from float 0

2017-10-04 Thread Eric V. Smith
Change by Eric V. Smith : -- nosy: +eric.smith ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.py

[issue31684] Scientific formatting of decimal 0 different from float 0

2017-10-03 Thread Mark Dickinson
Mark Dickinson added the comment: The aim here is to capture the original Decimal value where possible, including the exponent information. (Unlike floats, trailing zeros in a `Decimal` instance are significant.) >>> from decimal import Decimal >>> Decimal('+0.000e+19') Decima

[issue31684] Scientific formatting of decimal 0 different from float 0

2017-10-03 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +facundobatista, mark.dickinson, rhettinger, skrah ___ Python tracker ___ ___ Python-bugs-list

[issue31684] Scientific formatting of decimal 0 different from float 0

2017-10-03 Thread Aaron Meurer
New submission from Aaron Meurer : >>> '{:+.19e}'.format(0.) '+0.000e+00' >>> import decimal >>> '{:+.19e}'.format(decimal.Decimal(0)) '+0.000e+19' Note the decimal uses e+19 instead of e+00. Obviously it's still mathematically correct, but it's annoying to have