Ken, As a frequent user of complex numbers, I go from real to complex and back and very deliberately. In the most common scenarios, the end game involves complex numbers that should be real (imaginary parts being only roundoff error). I (cautiously) ignore the roundoff, compare the real parts and sometimes the modului of compex numbers. Your proposed implementation is ok, but I have a hard time seeing it being useful. Bill -----Original Message----- From: pharo-project-bounces@lists.gforge.inria.fr [mailto:pharo-project-bounces@lists.gforge.inria.fr] On Behalf Of Igor Stasenko Sent: Saturday, August 15, 2009 5:04 AM To: Pharo-project@lists.gforge.inria.fr Subject: Re: [Pharo-project] #< if at first you dont succeed.. 2009/8/15 Ken.Dickey <Ken.Dickey@whidbey.com>:
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?
By reading a comment: "Not defined on Complex numbers" i wonder why implementation is different than following: Complex>> < aNumber "Not defined on Complex numbers" self shouldNotImplement ;) But yes, given the fact that Complex numbers could be used by someone in code as real numbers, and therefore expecting #< to work, an implementation proposed by you is plausible.
-KenD
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Best regards, Igor Stasenko AKA sig. _______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project