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

2010-04-13 Thread Steve Holden
Guido van Rossum wrote: > On Tue, Mar 16, 2010 at 2:32 PM, Steven D'Aprano wrote: >> But mixed arithmetic runs into the problem, what do you want the result >> type to be? Given (say) decimal+float, returning either a Decimal or a >> float will be the wrong thing to do some of the time, so better

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

2010-03-23 Thread Bob Ippolito
On Sat, Mar 20, 2010 at 4:38 PM, Mark Dickinson wrote: > On Sat, Mar 20, 2010 at 7:56 PM, Guido van Rossum wrote: >> I propose to reduce all hashes to the hash of a normalized fraction, >> which we can define as a combination of the hashes for the numerator >> and the denominator. Then all we hav

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

2010-03-20 Thread Mark Dickinson
On Sat, Mar 20, 2010 at 7:56 PM, Guido van Rossum wrote: > I propose to reduce all hashes to the hash of a normalized fraction, > which we can define as a combination of the hashes for the numerator > and the denominator. Then all we have to do is figure fairly efficient > ways to convert floats a

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

2010-03-20 Thread Guido van Rossum
On Sat, Mar 20, 2010 at 4:16 AM, Mark Dickinson wrote: > True.  The reason I was concentrating on the hashes is that it's not > immediately obvious that it's even *possible* to find a decent hash > function that's efficient to compute and gives equal results for > numerically equal inputs (regardl

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

2010-03-20 Thread Case Vanhorsen
On Sat, Mar 20, 2010 at 10:05 AM, Mark Dickinson wrote: > On Sat, Mar 20, 2010 at 3:17 PM, Case Vanhorsen wrote: >> On Sat, Mar 20, 2010 at 4:06 AM, Mark Dickinson wrote: >>> What external modules are there that rely on existing hash behaviour? >> >> I'm only aware of  gmpy and SAGE. >> >>> And

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

2010-03-20 Thread Mark Dickinson
On Sat, Mar 20, 2010 at 3:17 PM, Case Vanhorsen wrote: > On Sat, Mar 20, 2010 at 4:06 AM, Mark Dickinson wrote: >> What external modules are there that rely on existing hash behaviour? > > I'm only aware of  gmpy and SAGE. > >> And exactly what behaviour do they rely on? > > Instead of calculatin

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

2010-03-20 Thread Terry Reedy
On 3/20/2010 7:06 AM, Mark Dickinson wrote: Will this change the result of hashing a long? I know that both gmpy and SAGE use their own hash implementations for performance reasons. I understand that CPython's hash function is an implementation detail, but there are external modules that rely on

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

2010-03-20 Thread Case Vanhorsen
On Sat, Mar 20, 2010 at 4:06 AM, Mark Dickinson wrote: > On Fri, Mar 19, 2010 at 1:17 PM, Case Vanhorsen wrote: >> On Fri, Mar 19, 2010 at 3:07 AM, Mark Dickinson wrote: >>> On Fri, Mar 19, 2010 at 9:37 AM, Mark Dickinson wrote: Making hashes of int, float, Decimal *and* Fraction all

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

2010-03-20 Thread Mark Dickinson
On Sat, Mar 20, 2010 at 12:10 AM, Greg Ewing wrote: > Nick Coghlan wrote: >> >> Mark Dickinson wrote: > >> It seems to me that given the existing conflation of numeric equivalence >> and containment testing, going the whole hog and fixing the set >> membership problem for all of our rational types

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

2010-03-20 Thread Mark Dickinson
On Fri, Mar 19, 2010 at 1:17 PM, Case Vanhorsen wrote: > On Fri, Mar 19, 2010 at 3:07 AM, Mark Dickinson wrote: >> On Fri, Mar 19, 2010 at 9:37 AM, Mark Dickinson wrote: >>> Making hashes of int, >>> float, Decimal *and* Fraction all compatible with one another, >>> efficient for ints and floats

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

2010-03-19 Thread Greg Ewing
Nick Coghlan wrote: Mark Dickinson wrote: It seems to me that given the existing conflation of numeric equivalence and containment testing, going the whole hog and fixing the set membership problem for all of our rational types would be the right thing to do. Isn't this only solving half the

Re: [Python-Dev] Decimal [...] float comparisons in py3k.

2010-03-19 Thread Antoine Pitrou
Guido van Rossum python.org> writes: > > Antoine, I think your email client turns replies whose subject > contains '&' into new subjects containing sequences like this: > > & amp; lt; -& amp; gt; > > There's a number of new threads with ever-more occurrences of "amp" in > the subject,

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

2010-03-19 Thread Adam Olsen
On Thu, Mar 18, 2010 at 12:41, Mark Dickinson wrote: > I'm only seeing two arguments against this at the moment: (1) it has > the potential to break code that relies on being able to sort > heterogeneous lists.  But given that heterogeneous lists can't be > sorted stably anyway (see my earlier pos

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

2010-03-19 Thread Case Vanhorsen
On Fri, Mar 19, 2010 at 3:07 AM, Mark Dickinson wrote: > On Fri, Mar 19, 2010 at 9:37 AM, Mark Dickinson wrote: >> Making hashes of int, >> float, Decimal *and* Fraction all compatible with one another, >> efficient for ints and floats, and not grossly inefficient for >> Fractions and Decimals, i

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

2010-03-19 Thread Nick Coghlan
Mark Dickinson wrote: > On Fri, Mar 19, 2010 at 9:37 AM, Mark Dickinson wrote: > For ints, this hash function is almost identical to what Python > already has, except that the current int hash does a reduction modulo > 2**32-1 or 2**64-1 rather than 2**31-1. For all small ints, hash(n) > == n, as

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

2010-03-19 Thread Mark Dickinson
On Fri, Mar 19, 2010 at 9:37 AM, Mark Dickinson wrote: > Making hashes of int, > float, Decimal *and* Fraction all compatible with one another, > efficient for ints and floats, and not grossly inefficient for > Fractions and Decimals, is kinda hairy, though I have a couple of > ideas of how it cou

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

2010-03-19 Thread Mark Dickinson
On Thu, Mar 18, 2010 at 9:48 PM, Nick Coghlan wrote: > Note that even in Py3k there are some fairly serious weirdnesses kicking > around due to the intransitive nature of numeric equality though: Yep. My personal favourite is: >>> from decimal import Decimal as dec >>> set((1, 1.0, dec(1))) ==

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

2010-03-18 Thread Glenn Linderman
On 3/18/2010 6:18 PM, Antoine Pitrou wrote: Glenn Linderman g.nevcal.com> writes: On 3/18/2010 2:48 PM, Nick Coghlan wrote: When there is a clear, correct way (based on Decimal.from_float) to make numeric comparison behave in accordance with the rules of mathematics, do we really wa

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

2010-03-18 Thread Antoine Pitrou
Glenn Linderman g.nevcal.com> writes: > > On 3/18/2010 2:48 PM, Nick Coghlan wrote: > > When there is a clear, correct way (based on Decimal.from_float) to make > > numeric comparison behave in accordance with the rules of mathematics, > > do we really want to preserve strange, unintuitive behavi

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

2010-03-18 Thread Terry Reedy
On 3/18/2010 5:48 PM, Nick Coghlan wrote: Mark Dickinson wrote: Could everyone live with making float<->Decimal comparisons raise an exception in 2.7? I could, with the caveat that *if* this causes problems for real world code, then changing it to produce the correct answer (as per your patch)

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

2010-03-18 Thread Glenn Linderman
On 3/18/2010 2:48 PM, Nick Coghlan wrote: When there is a clear, correct way (based on Decimal.from_float) to make numeric comparison behave in accordance with the rules of mathematics, do we really want to preserve strange, unintuitive behaviour like the above? Cheers, Nick. I'm aware of

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

2010-03-18 Thread Glenn Linderman
On 3/18/2010 12:34 PM, Steven D'Aprano wrote: 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 com

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

2010-03-18 Thread Nick Coghlan
Mark Dickinson wrote: > Could everyone live with making float<->Decimal comparisons raise an > exception in 2.7? I could, with the caveat that *if* this causes problems for real world code, then changing it to produce the correct answer (as per your patch) should be applied as a bug fix in both 2.

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

2010-03-18 Thread Glenn Linderman
On 3/18/2010 12:45 PM, Robert Kern wrote: On 2010-03-18 13:27 PM, Glenn Linderman wrote: 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

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

2010-03-18 Thread Robert Kern
On 2010-03-18 13:27 PM, Glenn Linderman wrote: 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 Not at all. This is qu

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

2010-03-18 Thread Steven D'Aprano
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, i

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

2010-03-18 Thread Steven D'Aprano
On Fri, 19 Mar 2010 05:41:08 am Mark Dickinson wrote: > I'd really like to get this sorted for 2.7: as far as I'm concerned, > either of the proposed behaviours (raise an exception, or allow > comparisons) would be an improvement on the current 2.7 behaviour. > > Could everyone live with making f

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

2010-03-18 Thread Michael Foord
On 18/03/2010 18:44, Antoine Pitrou wrote: [snip...] Seems like it would be better to raise an exception, and in the documentation for the exception point out that turning off the exception (if it should be decided that that should be possible, which could be good for compatibility), would regre

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

2010-03-18 Thread Antoine Pitrou
Glenn Linderman g.nevcal.com> writes: > > For all the reasons that mixed decimal and float arithmetic is bad, > mixed decimal and float comparisons are also bad. To do proper > comparisons, you need to know the number of significant digits of both > numbers, and the precision and numeric rang

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

2010-03-18 Thread Mark Dickinson
On Thu, Mar 18, 2010 at 5:55 PM, Raymond Hettinger wrote: > My thought is that intentional mixed compares of float and decimal > are very rare relative to unintentional cases.  IOW, most of the > time that x (or the user simply doesn't understand what his or her code is > actually doing).  That us

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

2010-03-18 Thread Glenn Linderman
On 3/18/2010 5:23 AM, Steven D'Aprano wrote: On Thu, 18 Mar 2010 08:58:25 am Raymond Hettinger wrote: On Mar 17, 2010, at 1:59 PM, Steven D'Aprano wrote: On Thu, 18 Mar 2010 07:44:21 am Raymond Hettinger wrote: The spectrum of options from worst to best is 1) compare but give

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

2010-03-18 Thread Raymond Hettinger
On Mar 18, 2010, at 5:23 AM, Steven D'Aprano wrote: > On Thu, 18 Mar 2010 08:58:25 am Raymond Hettinger wrote: >> On Mar 17, 2010, at 1:59 PM, Steven D'Aprano wrote: >>> On Thu, 18 Mar 2010 07:44:21 am Raymond Hettinger wrote: The spectrum of options from worst to best is 1) compare but

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

2010-03-18 Thread Steven D'Aprano
On Thu, 18 Mar 2010 08:58:25 am Raymond Hettinger wrote: > On Mar 17, 2010, at 1:59 PM, Steven D'Aprano wrote: > > On Thu, 18 Mar 2010 07:44:21 am Raymond Hettinger wrote: > >> The spectrum of options from worst to best is > >> 1) compare but give the wrong answer > >> 2) compare but give the right

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

2010-03-17 Thread Raymond Hettinger
On Mar 17, 2010, at 5:02 PM, Greg Ewing wrote: > Raymond Hettinger wrote: > >> Python 3 doesn't need it because it is possible to not give a result >> at all. Python 2 does need it because we have to give *some* >> result. > > That's not true -- it's possible for comparisons to raise > an exce

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

2010-03-17 Thread Greg Ewing
Raymond Hettinger wrote: Python 3 doesn't need it because it is possible to not give a result at all. Python 2 does need it because we have to give *some* result. That's not true -- it's possible for comparisons to raise an exception in 2.x, and they sometimes do already: Python 2.5.4 (r254:

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

2010-03-17 Thread Greg Ewing
Guido van Rossum wrote: in some "intuitive complexity" sense an int is a simpler type than a float and a float is a simpler type than a Decimal I don't think this analogy holds. In a mathematical sense, ints are a subset of reals, but binary and decimal floats are just alternative approximate r

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

2010-03-17 Thread Greg Ewing
Steven D'Aprano wrote: More explicit than someDecimal == someFloat? Seems pretty explicit to me. Yes. I mean at least specifying either float(someDecimal) == someFloat or someDecimal == Decimal(someFloat). Preferably also whether the conversion is to be as exact as possible or on a minimum-d

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

2010-03-17 Thread Guido van Rossum
On Wed, Mar 17, 2010 at 1:44 PM, Raymond Hettinger wrote: > > On Mar 17, 2010, at 12:34 PM, Terry Reedy wrote: > > I agree. Improving 2.7 and not 3.2+ would give people a reason to not move > to 3.x. > > > FWIW, I think this is mischaracterizing the proposal. > The spectrum of options from worst

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

2010-03-17 Thread Raymond Hettinger
On Mar 17, 2010, at 1:59 PM, Steven D'Aprano wrote: > On Thu, 18 Mar 2010 07:44:21 am Raymond Hettinger wrote: >> The spectrum of options from worst to best is >> 1) compare but give the wrong answer >> 2) compare but give the right answer >> 3) refuse to compare. > > Why is 3 the best? If there

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

2010-03-17 Thread Nick Coghlan
Steven D'Aprano wrote: > On Thu, 18 Mar 2010 07:44:21 am Raymond Hettinger wrote: >> The spectrum of options from worst to best is >> 1) compare but give the wrong answer >> 2) compare but give the right answer >> 3) refuse to compare. > > Why is 3 the best? If there is a right answer to give, sur

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

2010-03-17 Thread Steven D'Aprano
On Thu, 18 Mar 2010 07:44:21 am Raymond Hettinger wrote: > The spectrum of options from worst to best is > 1) compare but give the wrong answer > 2) compare but give the right answer > 3) refuse to compare. Why is 3 the best? If there is a right answer to give, surely giving the right answer it i

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

2010-03-17 Thread Raymond Hettinger
On Mar 17, 2010, at 12:34 PM, Terry Reedy wrote: > > I agree. Improving 2.7 and not 3.2+ would give people a reason to not move to > 3.x. > FWIW, I think this is mischaracterizing the proposal. The spectrum of options from worst to best is 1) compare but give the wrong answer 2) compare but g

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

2010-03-17 Thread Terry Reedy
On 3/17/2010 1:09 PM, Guido van Rossum wrote: Ok, I'll try to stay out of the discussion of which solution is best of our users, and if the outcome is that mixed operations in general are bad but mixed comparisons are good, I'll trust you. However I want to reiterate that you really shouldn't im

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

2010-03-17 Thread Guido van Rossum
On Wed, Mar 17, 2010 at 8:04 AM, Mark Dickinson wrote: > On Tue, Mar 16, 2010 at 5:15 PM, Guido van Rossum wrote: >> Definitely some. Stricter comparison rules are a frequent cause of >> problems when code is first ported to 3.x. While you'd think that code >> comparing a float and a Decimal is *

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

2010-03-17 Thread Mark Dickinson
On Tue, Mar 16, 2010 at 5:15 PM, Guido van Rossum wrote: > Definitely some. Stricter comparison rules are a frequent cause of > problems when code is first ported to 3.x. While you'd think that code > comparing a float and a Decimal is *already* broken, there's a > surprising number of situations

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

2010-03-17 Thread Mark Dickinson
On Wed, Mar 17, 2010 at 11:43 AM, Steven D'Aprano wrote: > Having said all that, I've just re-read the PEP, and spotted a fly in > the ointment... hash. > > If we allow Decimals to compare equal to floats, that presumably implies > that they need to hash equal. That may be simple enough for intege

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

2010-03-17 Thread Mark Dickinson
On Wed, Mar 17, 2010 at 12:36 AM, Raymond Hettinger wrote: > > On Mar 16, 2010, at 9:41 AM, Guido van Rossum wrote: >> >> Also supporting comparisons but not other mixed operations is going to >> be confusing. If you are sticking to that behavior I think mixed >> comparisons should also be ruled o

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

2010-03-17 Thread Mark Dickinson
On Tue, Mar 16, 2010 at 10:32 PM, Steven D'Aprano wrote: > On Wed, 17 Mar 2010 03:23:30 am Mark Dickinson wrote: >> On Tue, Mar 16, 2010 at 4:11 PM, Mark Dickinson >> wrote: [...] >> >> Decimal.from_float(1.1) == 1.1 >> > >> > False >> >> Whoops.  To clarify, this is the pre-patch behaviour;

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

2010-03-17 Thread Mark Dickinson
On Tue, Mar 16, 2010 at 10:16 PM, Greg Ewing wrote: > Mark Dickinson wrote: >> >> On Tue, Mar 16, 2010 at 3:58 PM, P.J. Eby wrote: >> >>> 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-poin

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

2010-03-17 Thread Steven D'Aprano
On Wed, 17 Mar 2010 10:01:12 am Guido van Rossum wrote: > On Tue, Mar 16, 2010 at 2:32 PM, Steven D'Aprano wrote: > > But mixed arithmetic runs into the problem, what do you want the > > result type to be? Given (say) decimal+float, returning either a > > Decimal or a float will be the wrong thin

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

2010-03-17 Thread Steven D'Aprano
On Wed, 17 Mar 2010 12:27:01 pm Raymond Hettinger wrote: > On Mar 16, 2010, at 3:16 PM, Greg Ewing wrote: > > Seems to me that this education would mostly consist of saying > > "don't compare floats and decimals", which is why I think that > > disallowing them in the first place would be better. >

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

2010-03-16 Thread Raymond Hettinger
On Mar 16, 2010, at 3:16 PM, Greg Ewing wrote: > > Seems to me that this education would mostly consist of saying > "don't compare floats and decimals", which is why I think that > disallowing them in the first place would be better. That makes sense. I do worry that 2.x currently does make the

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

2010-03-16 Thread Guido van Rossum
On Tue, Mar 16, 2010 at 5:36 PM, Raymond Hettinger wrote: > > > > On Mar 16, 2010, at 9:41 AM, Guido van Rossum wrote: > >> I'd say if you're not going to forward-port this to Python 3, it >> shouldn't go into Python 2 -- in that case it would make more sense to >> me to back-port the exception-ra

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

2010-03-16 Thread Raymond Hettinger
On Mar 16, 2010, at 9:41 AM, Guido van Rossum wrote: > I'd say if you're not going to forward-port this to Python 3, it > shouldn't go into Python 2 -- in that case it would make more sense to > me to back-port the exception-raising behavior. Python 3 doesn't need it because it is possible to

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

2010-03-16 Thread Guido van Rossum
On Tue, Mar 16, 2010 at 2:32 PM, Steven D'Aprano wrote: > But mixed arithmetic runs into the problem, what do you want the result > type to be? Given (say) decimal+float, returning either a Decimal or a > float will be the wrong thing to do some of the time, so better to > prohibit mixed arithmeti

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

2010-03-16 Thread Steven D'Aprano
On Wed, 17 Mar 2010 09:16:11 am Greg Ewing wrote: > Mark Dickinson wrote: > > On Tue, Mar 16, 2010 at 3:58 PM, P.J. Eby wrote: > >>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 co

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

2010-03-16 Thread Nick Coghlan
Steven D'Aprano wrote: > But no such problems arise with comparisons, which will always return a > bool, and will avoid the current ... interesting ... behaviour. In 3.1: > Decimal(1) == 1 == 1.0 > True Decimal(1) == 1.0 > False Decimal.from_float(1.0) == 1 == 1.0 > True Decim

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

2010-03-16 Thread Steven D'Aprano
On Wed, 17 Mar 2010 03:23:30 am Mark Dickinson wrote: > On Tue, Mar 16, 2010 at 4:11 PM, Mark Dickinson > wrote: [...] > > Decimal.from_float(1.1) == 1.1 > > > > False > > Whoops. To clarify, this is the pre-patch behaviour; post-patch, > this gives True. Whew! You had me worried there for

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

2010-03-16 Thread Greg Ewing
Mark Dickinson wrote: On Tue, Mar 16, 2010 at 3:58 PM, P.J. Eby wrote: 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 progr

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

2010-03-16 Thread Greg Ewing
Mark Dickinson wrote: On the one hand there's something to be said for maintaining a clean separation between the float and Decimal types, allowing only explicit conversions from one to the other; mixed-type arithmetic between floats and Decimals was very deliberately not permitted in the origi

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

2010-03-16 Thread Guido van Rossum
On Tue, Mar 16, 2010 at 9:07 AM, Mark Dickinson wrote: > On Tue, Mar 16, 2010 at 4:41 PM, Guido van Rossum wrote: >> I'd say if you're not going to forward-port this to Python 3, it >> shouldn't go into Python 2 -- in that case it would make more sense to >> me to back-port the exception-raising

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

2010-03-16 Thread Mark Dickinson
On Tue, Mar 16, 2010 at 4:41 PM, Guido van Rossum wrote: > I'd say if you're not going to forward-port this to Python 3, it > shouldn't go into Python 2 -- in that case it would make more sense to > me to back-port the exception-raising behavior. That's also a possible solution, and the one that

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

2010-03-16 Thread Guido van Rossum
I'd say if you're not going to forward-port this to Python 3, it shouldn't go into Python 2 -- in that case it would make more sense to me to back-port the exception-raising behavior. Also supporting comparisons but not other mixed operations is going to be confusing. If you are sticking to that b

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

2010-03-16 Thread Mark Dickinson
On Tue, Mar 16, 2010 at 4:18 PM, Victor Stinner wrote: > If comparaison of Decimal and float can have "unpredictable" result, I would > suggest the same behaviour (raise an error). Well, it's not really `unpredictable': the new behaviour is perfectly predictable and sane, provided only that you

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

2010-03-16 Thread Mark Dickinson
On Tue, Mar 16, 2010 at 4:11 PM, Mark Dickinson wrote: [...] Decimal.from_float(1.1) == 1.1 > False Whoops. To clarify, this is the pre-patch behaviour; post-patch, this gives True. Mark ___ Python-Dev mailing list Python-Dev@python.org http://

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

2010-03-16 Thread Victor Stinner
Le mardi 16 mars 2010 16:58:22, P.J. Eby a écrit : > 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.from_float(.3)" > > Does Decimal.from_float() use the "shortest decimal representation" > app

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

2010-03-16 Thread Mark Dickinson
On Tue, Mar 16, 2010 at 3:58 PM, P.J. Eby 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.from_float(.3)" > > Does Decimal.from_float() use the "shortest decimal representation" > app

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

2010-03-16 Thread P.J. Eby
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.from_float(.3)" Does Decimal.from_float() use the "shortest decimal representation" approach? If not, it might be confusing if a number that prints a

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

2010-03-16 Thread Mark Dickinson
On Tue, Mar 16, 2010 at 2:58 PM, Facundo Batista wrote: > On Tue, Mar 16, 2010 at 9:41 AM, Mark Dickinson wrote: > >> On the one hand there's something to be said for maintaining a clean >> separation between the float and Decimal types, allowing only explicit >> conversions from one to the other

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

2010-03-16 Thread Facundo Batista
On Tue, Mar 16, 2010 at 9:41 AM, Mark Dickinson wrote: > On the one hand there's something to be said for maintaining a clean > separation between the float and Decimal types, allowing only explicit > conversions from one to the other;  mixed-type arithmetic between > floats and Decimals was very