[Python-Dev] Decimal <-> float comparisons in py3k. (original) (raw)
Mark Dickinson dickinsm at gmail.com
Tue Mar 16 17:11:38 CET 2010
- Previous message: [Python-Dev] Decimal <-> float comparisons in py3k.
- Next message: [Python-Dev] Decimal <-> float comparisons in py3k.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Mar 16, 2010 at 3:58 PM, P.J. Eby <pje at telecommunity.com> wrote:
At 09:58 AM 3/16/2010 -0500, Facundo Batista wrote:
I'm +0 to allow these comparisons, being "Decimal(1) < .3" the same as "Decimal(1) < Decimal.fromfloat(.3)" Does Decimal.fromfloat() use the "shortest decimal representation" approach?
No. It does exact conversions:
Decimal.fromfloat(1.1) Decimal('1.100000000000000088817841970012523233890533447265625') Decimal.fromfloat(1.1) == 1.1 False Decimal('1.1') == float('1.1') # returns False both pre- and post-patch False
If not, it might be confusing if a number that prints as '.1' compares unequal to Decimal('.1').
Agreed, but this is just your everyday floating-point confusion, to be dealt with by social means (e.g., educating the programmer). Any technical solution that made "Decimal('1.1') == float('1.1')" evaluate to True would, I suspect, be a cure worse than the original disease.
Mark
- Previous message: [Python-Dev] Decimal <-> float comparisons in py3k.
- Next message: [Python-Dev] Decimal <-> float comparisons in py3k.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]