473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Re: numeric emulation and the rich comparison operators

En Thu, 10 Jul 2008 17:37:42 -0300, Ethan Furman <et***@stoneleaf.us>
escribi�:
Greetings, List!

Still working on my Measure class, and my next question is... (drum roll
please ;)

What are the advantages of using __[eq|ne|lt|gt|le|ge]__ vs __cmp__?
If your objects obey the trichotomy law (an object MUST BE less than,
greater than, or equal to another one, and there is no other possibility)
then __cmp__ is enough, and easier to define than all the rich comparison
operations.
In other cases, __cmp__ is not suitable: by example, complex numbers can't
define "greater than" [in a way that preserves the meaning for real
numbers]; you can only use "equal" or "not equal". You can't use __cmp__
for this, because it *has* to return either >0 or <0 (implying "greater
than" or "less than"). In this case it's best to use the rich comparison
operators: define __eq__ and __ne__ and make all other comparisons between
complex numbers raise an exception.

--
Gabriel Genellina

Jul 11 '08 #1
0 1100

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sheldon | last post by:
Hi, I am trying to build a large array using concatenate function in python. So as I loop over the number of arrays, of which there are 12 (4 down and 3 across), I create 3 long arrays by...
11
by: Steven D'Aprano | last post by:
I'm writing a class that implements rich comparisons, and I find myself writing a lot of very similar code. If the calculation is short and simple, I do something like this: class Parrot: def...
8
by: Ethan Furman | last post by:
Greetings, List! I'm working on a numeric data type for measured values that will keep track of and limit results to the number of significant digits originally defined for the values in...
0
by: Ethan Furman | last post by:
Gabriel Genellina wrote: That's exactly the information I needed. Thanks!
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.