Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!newstand.syr.edu!news.maxwell.syr.edu!EU.net!uknet!usenet1.news.uk.psi.net!uknet!uknet!bcc.ac.uk!news
From: Channing Walton <cwalton@eleceng.ucl.ac.uk>
Subject: Re: Help needed in understanding isInteger or isFloat etc
Sender: news@ucl.ac.uk (Usenet News System)
Message-ID: <32E8C4B3.7845@eleceng.ucl.ac.uk>
Date: Fri, 24 Jan 1997 14:18:27 GMT
Reply-To: cwalton@eleceng.ucl.ac.uk
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
References: <32E6380E.30AB@eleceng.ucl.ac.uk> <32E7A233.35BB@isis.star.fedex.com> <32E89871.5BD4@eleceng.ucl.ac.uk>
Mime-Version: 1.0
X-Mailer: Mozilla 3.01Gold (Win16; I)
Organization: UCL
Lines: 38

> Matt Butler wrote:
> 
> >  Here's another idea in addition to implementing Number>>isComplex to
> > answer false.
> >
> > Add these methods:
> >
> > Number>>real
> >
> >         ^self
> >
> > Number>>imag
> >
> >         ^0
> >
> > Complex>>+ aNumber
> >         "Answer the result of adding
> >          the receiver to aNumber."
> >          ^Complex real: (real+aNumber real) imag: (imag + aNumber imag)
> >
> >  I don't know if this is valid complex number mathematics, but the idea
> > is that for a non-complex number, the real method just returns self and
> > the imag method returns zero, so you don't need to check the type when
> > adding.  That is, in the + aNumber method, two complex numbers will be
> > added normally.  If a non-complex is passed in, then the complex
> > number's real portion will have the value of the argument added to
> > itself, and the imaginary component will not change as the imag method
> > for the non-complex number argument returns zero.
> >
> 

Excellent. I have implemented the above and it works. I can use
fractions, integers
or doubles mixed up in my complex numbers and it all works.  

Thanks Matt.

channing

