This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients eric.smith, mark.dickinson, seperman, skrah, xtreak
Date 2019-04-14.08:19:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1555229971.82.0.950229052423.issue36622@roundup.psfhosted.org>
In-reply-to
Content
Indeed it's deliberate. When the Decimal type was introduced, the "at least two exponent digits" behaviour of float formatting was already long established. But the specification that the Decimal type was based on (and the extensive test cases from the same source) use the minimum number of exponent digits instead.

If we want to make the two things consistent, that means either deliberately introducing incompatibilities with the Decimal specification, or changing long-standing behaviour for float.

There's no reason in principle that we couldn't modify the float formatting to use a single digit in the exponent (assuming that exponent is smaller than 10 in absolute value). I'd expect that that would upset more people than it would help, though.

My guess is that the "at least 2 digits" rule in C99 7.24.2 is there to make it easier to align tables of values formatted in scientific notation. I can't think of another reason for force at least two digits.

For your use-case, could you convert all `float` objects to `Decimal` objects before comparison? The float to Decimal conversion doesn't lose any information (unlike the reverse conversion).

Closing this as "not a bug". There's certainly room for proposing and discussing changes to the behaviour, but that's probably best done on the python-ideas mailing list rather than the bug tracker.
History
Date User Action Args
2019-04-14 08:19:31mark.dickinsonsetrecipients: + mark.dickinson, eric.smith, skrah, xtreak, seperman
2019-04-14 08:19:31mark.dickinsonsetmessageid: <1555229971.82.0.950229052423.issue36622@roundup.psfhosted.org>
2019-04-14 08:19:31mark.dickinsonlinkissue36622 messages
2019-04-14 08:19:31mark.dickinsoncreate