Boost logo

Boost :

From: Guillaume Melquiond (guillaume.melquiond_at_[hidden])
Date: 2006-07-11 08:26:28

Le mardi 11 juillet 2006 à 14:21 +0300, Peter Dimov a écrit :

> >> Daryle Walker wrote:
> >>
> >>> [1] If you make a fake order for "std::complex<>", would you compare
> >>> real components then imaginary components, or would you use
> >>> magnitude then angle?
> >>
> >> Real, then imaginary. Compare with:
> >
> > Interesting. I would have chosen magnitude and then angle. Why
> > components.
> There are two reasons for that. First, composite types use lexicographical
> ordering by default, and std::complex is (de facto) a (real, imag) pair.
> Second, the magnitude/angle ordering has the property that if you have three
> numbers a, b, c, where a and b are very close to one another but not to c,
> it is possible to have a < c and c < b.

Your reasoning is a bit flawed, since this property is also true for the
lexicographic order. I assume that by "close" you mean with respect to
the natural distance on the complex numbers. Then a = (1,0) and b =
(2,0) are close (distance 1), yet c = (1.5,1e100) (distance ~1e100 from
both a and b) is lexicographically between the two of them.

> >> "If you make a FAKE order for std::string, would you compare left to
> >> right or right to left?"
> >
> > I don't think that is a legitimate comparison. In my world view,
> > strings have a natural order but complex numbers don't.
> Possibly. So you define "fake" as "unnatural", and define "natural" as
> "feels natural to me". This approach can work but it's a bit subjective,
> isn't it?
> Consider the progression:

This is not a progression. You can use vector<double> instead of
struct{}, since struct{} is nothing more than a cartesian product while
vector is a word monoid. But you can't use struct{} instead of
complex<double>. This change would lose the whole point of
complex<double>. It is supposed to (approximately) represent an
algebraically closed field with characteristic 0.

> complex<double>
> struct { double x, double y; }
> pair<double, double>
> tuple<double, double>
> vector<double>
> vector<char>
> string

Any set of computer data can be ordered. I don't think it means that
they should all have an operator<.

Best regards,


Boost list run by bdawes at, gregod at, cpdaniel at, john at