473,471 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1104

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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.