Message74641
More sensibility offenders:
>>> s = {fractions.Fraction(17,1), decimal.Decimal(17)}
>>> s-{17}
set()
Removing one thing removes two.
>>> s.remove(17)
>>> 17 in s
True
Removing something leaves it there.
>>> s
{Fraction(17, 1)} # random choice
Removing one thing and subtracting the set with that one thing give
different results.
>>> s = {decimal.Decimal(17), fractions.Fraction(17,1)}
>>> s.remove(17)
>>> s
{Decimal('17')}
The behavior of 'set' s depends on the order items are added.
> Facundo's suggested code:
if isinstance(other, float) and int(other)==other:
other = int(other)
would be more efficient, I assume as
if isinstance(other,float):
ifloat = int(other)
if other == ifloat:
other = ifloat
or if the CAPI has an efficient 'float_isint' function that accesses the
bits of a float, as the C equivalent of
if isinstance(other, float) and float_isint(other):
other = int(other)
I remember float-Decimal comparison being rejected/deferred in part for
being problematical for fractional values. That is why I suggested
implementing it, at least for the present, for integral floats (and
Fractions) only, which are relatively easy to detect. |
|
Date |
User |
Action |
Args |
2008-10-10 19:57:34 | terry.reedy | set | recipients:
+ terry.reedy, georg.brandl, rhettinger, facundobatista, mark.dickinson |
2008-10-10 19:57:34 | terry.reedy | set | messageid: <1223668654.17.0.0770237228198.issue4087@psf.upfronthosting.co.za> |
2008-10-10 19:57:33 | terry.reedy | link | issue4087 messages |
2008-10-10 19:57:32 | terry.reedy | create | |
|