Mark Dickinson <dicki...@gmail.com> added the comment:

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.

----------
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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

Reply via email to