Re: Comparing float and decimal

2008-10-03 Thread greg
Terry Reedy wrote: Documenting the problem properly would mean changing the set documentation ... from their current math set based definitions to implementation based definitions It could be documented that the mathematical definitions hold only if the equality relations between all the elem

Re: Comparing float and decimal

2008-10-03 Thread greg
Mark Dickinson wrote: Option (2) appeals to me, but I can't see how to implement it. It could be implemented for the special case of floats and Decimals by keeping flags in each set indicating whether any elements of those types have been added. But doing this just for those two types would b

Re: Comparing float and decimal

2008-10-01 Thread Mark Dickinson
On Sep 30, 8:07 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > Documenting the problem properly would mean changing the set > documentation to change at least the definitions of union (|), issubset > (<=), issuperset (>=), and symmetric_difference (^) from their current > math set based definitions t

Re: Comparing float and decimal

2008-09-30 Thread Terry Reedy
Mark Dickinson wrote: On Sep 30, 9:21 am, Terry Reedy <[EMAIL PROTECTED]> wrote: If no one beats me to it, I will probably file a bug report or two, but I am still thinking about what to say and to suggest. I can't see many good options here. Some possibilities: Thanks for responding. Agre

Re: Comparing float and decimal

2008-09-30 Thread Mark Dickinson
On Sep 30, 9:21 am, Terry Reedy <[EMAIL PROTECTED]> wrote: > If no one beats me to it, I will probably file a bug report or two, but > I am still thinking about what to say and to suggest. I can't see many good options here. Some possibilities: (0) Do nothing besides documenting the problem some

Re: Comparing float and decimal

2008-09-30 Thread Terry Reedy
Gabriel Genellina wrote: En Thu, 25 Sep 2008 08:02:49 -0300, Mark Dickinson <[EMAIL PROTECTED]> escribió: On Sep 23, 1:58 pm, Robert Lehmann <[EMAIL PROTECTED]> wrote: I don't see why transitivity should apply to Python objects in general. Hmmm. Lack of transitivity does produce some, um, in

Re: Comparing float and decimal

2008-09-29 Thread Gabriel Genellina
En Thu, 25 Sep 2008 08:02:49 -0300, Mark Dickinson <[EMAIL PROTECTED]> escribió: On Sep 23, 1:58 pm, Robert Lehmann <[EMAIL PROTECTED]> wrote: I don't see why transitivity should apply to Python objects in general. Hmmm. Lack of transitivity does produce some, um, interesting results when pl

Re: Comparing float and decimal

2008-09-26 Thread Tim Roberts
Mark Dickinson <[EMAIL PROTECTED]> wrote: >On Sep 25, 8:55 am, Tim Roberts <[EMAIL PROTECTED]> wrote: >> Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> >0.1 actually is >> >> >In [98]: '%.50f' % 0.1 >> >Out[98]: '0.1555111512312578270211815834045410' >> >? >> >>  0.1 i

Re: Comparing float and decimal

2008-09-26 Thread Tim Roberts
Mark Dickinson <[EMAIL PROTECTED]> wrote: >On Sep 25, 8:55 am, Tim Roberts <[EMAIL PROTECTED]> wrote: >> Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> >0.1 actually is >> >> >In [98]: '%.50f' % 0.1 >> >Out[98]: '0.1555111512312578270211815834045410' >> >? >> >> Actually, i

Re: Comparing float and decimal

2008-09-25 Thread Terry Reedy
Mark Dickinson wrote: On Sep 24, 6:18 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: If there is not now, there could be in the future, and the decimal authors are committed to follow the standard wherever it goes. Therefore, the safe course, to avoid possible future deprecations due to doing too mu

Re: Comparing float and decimal

2008-09-25 Thread Mark Dickinson
On Sep 23, 1:58 pm, Robert Lehmann <[EMAIL PROTECTED]> wrote: > I don't see why transitivity should apply to Python objects in general. Hmmm. Lack of transitivity does produce some, um, interesting results when playing with sets and dicts. Here are sets s and t such that the unions s | t and t |

Re: Comparing float and decimal

2008-09-25 Thread Nick Craig-Wood
Tim Roberts <[EMAIL PROTECTED]> wrote: > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > > >On Tue, 23 Sep 2008 07:08:07 -0700, Michael Palmer wrote: > > > >>> > This seems to break the rule that if A is equal to B and B is equal > >>> > to C then A is equal to C. > >>> > >>> I don't see w

Re: Comparing float and decimal

2008-09-25 Thread Mark Dickinson
On Sep 25, 8:55 am, Tim Roberts <[EMAIL PROTECTED]> wrote: > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > >0.1 actually is > > >In [98]: '%.50f' % 0.1 > >Out[98]: '0.1555111512312578270211815834045410' > >? > > Actually, it's not.  Your C run-time library is generating rand

Re: Comparing float and decimal

2008-09-25 Thread Mark Dickinson
On Sep 24, 6:18 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > If there is not now, there could be in the future, and the decimal > authors are committed to follow the standard wherever it goes. > Therefore, the safe course, to avoid possible future deprecations due to > doing too much, is to only do

Re: Comparing float and decimal

2008-09-25 Thread Tim Roberts
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > >On Tue, 23 Sep 2008 07:08:07 -0700, Michael Palmer wrote: > >>> > This seems to break the rule that if A is equal to B and B is equal >>> > to C then A is equal to C. >>> >>> I don't see why transitivity should apply to Python objects in genera

Re: Comparing float and decimal

2008-09-24 Thread Steven D'Aprano
On Wed, 24 Sep 2008 04:30:03 -0500, Nick Craig-Wood wrote: > Both the Fraction module and the Decimal module could represent floats > exactly and reversibly since floats are of the form > > mantissa * 2**exponent > > which is exactly representable as a fraction (rational) and also as > > m

Re: Comparing float and decimal

2008-09-24 Thread Terry Reedy
Mark Dickinson wrote: On Sep 23, 7:31 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: Decimal is something of an anomaly in Python because it was written to exactly follow an external standard, with no concessions to what would be sensible for Python. It is possible that that standard mandates that

Re: Comparing float and decimal

2008-09-24 Thread Mark Dickinson
On Sep 23, 7:31 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > Decimal is something of an anomaly in Python because it was written to > exactly follow an external standard, with no concessions to what would > be sensible for Python.  It is possible that that standard mandates that > Decimals not comp

Re: Comparing float and decimal

2008-09-24 Thread Nick Craig-Wood
Terry Reedy <[EMAIL PROTECTED]> wrote: > The new fractions module acts differently, which is to say, as most > would want. > > >>> from fractions import Fraction as F > >>> F(1) == 1.0 > True > >>> F(1.0) > Traceback (most recent call last): > File "", line 1, in > F(1.0) >

Re: Comparing float and decimal

2008-09-23 Thread Marc 'BlackJack' Rintsch
On Tue, 23 Sep 2008 07:08:07 -0700, Michael Palmer wrote: >> > This seems to break the rule that if A is equal to B and B is equal >> > to C then A is equal to C. >> >> I don't see why transitivity should apply to Python objects in general. > > Well, for numbers it surely would be a nice touch, w

Re: Comparing float and decimal

2008-09-23 Thread Terry Reedy
Gerhard Häring wrote: D'Arcy J.M. Cain wrote: I'm not sure I follow this logic. Can someone explain why float and integer can be compared with each other and decimal can be compared to integer but decimal can't be compared to float? from decimal import Decimal i = 10 f = 10.0 d = Decimal("10.

Re: Comparing float and decimal

2008-09-23 Thread Michael Palmer
On Sep 23, 10:08 am, Michael Palmer <[EMAIL PROTECTED]> wrote: > May be the reason for Decimal to accept float arguments is that NOT to accept float arguments. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing float and decimal

2008-09-23 Thread Michael Palmer
> > This seems to break the rule that if A is equal to B and B is equal to C > > then A is equal to C. > > I don't see why transitivity should apply to Python objects in general. Well, for numbers it surely would be a nice touch, wouldn't it. May be the reason for Decimal to accept float argument

Re: Comparing float and decimal

2008-09-23 Thread Robert Lehmann
On Tue, 23 Sep 2008 07:20:12 -0400, D'Arcy J.M. Cain wrote: > I'm not sure I follow this logic. Can someone explain why float and > integer can be compared with each other and decimal can be compared to > integer but decimal can't be compared to float? In comparisons, `Decimal` tries to convert

Re: Comparing float and decimal

2008-09-23 Thread Gerhard Häring
D'Arcy J.M. Cain wrote: I'm not sure I follow this logic. Can someone explain why float and integer can be compared with each other and decimal can be compared to integer but decimal can't be compared to float? from decimal import Decimal i = 10 f = 10.0 d = Decimal("10.00") i == f True i ==