Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!hubcap!ncrcae!PEDEV!rogerson From: rogerson@PEDEV.Columbia.NCR.COM (Dale Rogerson) Newsgroups: comp.lang.pascal Subject: Re: complex numbers Message-ID: <2590@PEDEV.Columbia.NCR.COM> Date: 14 Jul 89 18:12:59 GMT References: <1301@draken.nada.kth.se> Reply-To: rogerson@PEDEV.Columbia.NCR.COM (Dale Rogerson) Organization: NCR Corp., Engineering & Manufacturing - Columbia, SC Lines: 48 In article <1301@draken.nada.kth.se> d88-eli@nada.kth.se (Erik Liljencrantz) writes: >Complex arithmetic can't be done the nice way (i.e. a:=b+c; and so on) in >standard pascal. Suggestions of Pascal-SC, C++ and Ada has been posted, but >what about Turbo Pascal 5.5. It's objectoriented (like C++) but is it >possible to define addition (and the other operations as well) for objects? It is not possible to overload the standard operations. Also no provisions are made for making any prefix or postfix operators. The language is also a little weak in any kind of overloading. I will check and see if an object can have two methods with the same name, but different number of parameters. >Or is it just possible to define objectspecific procedures and functions? > A,B,C:COMPLEX; { Our complex objecttype } > A:=B+C; { Not + but complex + } > A:=(B+C)/(B-C); { Very complex... } The above is not possible with turbo pascal 5.5. This is possible with C++ and the new version of Eiffel may do this. >Procedures with VAR-parameters aren't that nice...: > ComplexAdd(Tmp1,B,C); { ...this is ugly! } > ComplexSub(Tmp2,B,C); > ComplexDiv(A,Tmp1,Tmp2); And the way you must do it is the ugly way. The new OOPs features of TP are really not hurt that much by not having this feature. >If functions could return our COMPLEX type then it could look like this: > A,B,C:COMPLEX; > A:=ComplexAdd(B,C); > A:=ComplexDiv(ComplexAdd(B,C),ComplexSub(B,C)); I don't think that this will work either. My refernece manual for TP 5.5 does not say that functions have been extended to return objects, so I would bet that this is not possible. I will also check this out and see if it will work. Even, if these features do not work in TP 5.5 it is still a major improvment over the standard pascal. -----Dale Rogerson----