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 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"

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

Reply via email to