Pending your solution be accepted for the Complex implementation, I suggest the following changes in your code:

Complex>>asReal
"Answer real-part of self if imaginary is zero else, error"
imaginary isZero
ifTrue: [^real].
self error: 'Can''t convert to real'

Em 15/08/2009 06:04, Ken.Dickey < [email protected] > escreveu:


Taking a hint from the comments (yes, I do listen), here is a "less
complex" :) solution:

Complex>>
< aNumber
"Not defined on Complex numbers"

^self asReal < aNumber asReal

Complex>>
asReal
"Answer real-part of self if imaginary is zero else, error"
(imaginary = 0)
ifTrue: [^real]
ifFalse: [self error: 'Can''t convert to real']

Better?

-KenD

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

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

Reply via email to