2009/8/13  <[email protected]>:
> For the mathematical part yes. Now, submiting to all the list, I want to
> propose a modification in the code based on Smalltalk style (the comments
> w/"csr" are only for my explanation and should not go to the production
> code!):
>
> < other
> "Can only compare with pure real or imaginary parts"
> ((self imaginary = 0) and: [other imaginary = 0])
> ifTrue: [^ self real < other real].               "csr: if it's true you

i think, if imaginary part is zero , then Complex values should be
normalized back to real ones (obviously to conserve the memory), and
therefore the test 'self imaginary = 0' is redundant.

> returned, so no need the iFalse part"
> ((self real = 0) and: [other real = 0])
> ifTrue: [^self imaginary < other imaginary]. "csr: same here"
> ArithmeticError new signal: 'Complex numbers are not generally comparable'
> "csr: Only will happen if no one of the above blocks returned"
>

But back to the question:
in given form, i really don't see what is the meaning of #< operator
on Complex numbers?
Because , obviously, in first place, i expecting that #< method serves
to compare Complex numbers, not mix of real and complex,
but implemented in such form, the value of such method is nearly zero
(in complex plane ;).
So, the question remains the same: is it worth adding it, just for the
sake of complete protocol(s)?

P.S. diving into complex plane uncovers many potential pitfalls to
those who expecting a certain behavior of mathematical functions over
a real numbers.
In first place square and square root.
It is good that with introduction of a complex numbers we can be sure that
x sqrt squared = x
for any real x.

The complex numbers gives us a impression that from now on, the square
function and squared root functions is reversable.
But they are not for a complex numbers.
In practice this means, that one, who using a complex math in his
code, should know well the properties of complex numbers, because this
is not so trivial as with real numbers & school algebra. And such
people, basically don't need the things with questionable or
controversial behavior such as #< operators on a complex plane.
Then the aim of Complex package developer should be to not introduce
more confusion to people who is not using/learnt the complex numbers,
and leave attempts to help people who can - because they could care
for themselves well.


> HTH
>
> Em 12/08/2009 21:39, Ken.Dickey < [email protected] > escreveu:
>
> OK, here is a strict version. Complex>>< only compares numbers on the real
> or
> imaginal axis and throws an "incomparable" error otherwise. The
> ComplexTest>>textCompare checks obvious cases.
>
> Is this version (more) acceptable?
>
> As usual, please feel free to correct (or send me corrections) for better
> coding style (e.g a shorter/better error message) as well as any dumbness on
> my part.
>
> Cheers,
> -KenD
> ------------------------Complex
> < other
> "Can only compare with pure real or imaginary parts"
> ((self imaginary = 0) and: [other imaginary = 0])
> ifTrue: [^ self real < other real]
> ifFalse: [((self real = 0) and: [other real = 0])
> ifTrue: [^self imaginary < other imaginary]
> ifFalse: [ArithmeticError new
> signal: 'Complex numbers are not generally co mparable'.]
> ]
> ------------------------
>
>
>
> _______________________________________________
> Pharo-project mailing list
> [email protected]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



-- 
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to