[Python-Dev] Decimal <-> float comparisons in py3k.

Steven D'Aprano steve at pearwood.info
Thu Mar 18 20:34:19 CET 2010

On Fri, 19 Mar 2010 05:27:06 am Glenn Linderman wrote:

> > Do you envisage any problems from allowing this instead?
> >
> >>>> Decimal('1.1')<  2.2
> >
> > True
> Yes.
> As any non-naïve float user is aware, the proper form of float
> comparisons is not to use < or > or == or !=, but rather, instead of
> using < (to follow along with your example), one should use:
> Decimal('1.1') - 2.2 < epsilon

And yet we allow 

1.1 < 2.2

instead of forcing users to do the "proper form". One can only wonder 
why the various standards (actual and de-facto) for floating point 
allows comparisons at all.

But they do, and so does Python, and frankly even if the only reason is 
to satisfy lazy coders who don't have a requirement for high accuracy, 
then that's a good reason in my book, and one equally applicable to 
Decimal and float.

Steven D'Aprano

More information about the Python-Dev mailing list