Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!iuvax!purdue!mentor.cc.purdue.edu!pur-ee!pur-phy!murphy From: murphy@pur-phy (William J. Murphy) Newsgroups: comp.lang.pascal Subject: Re: complex numbers Message-ID: <2361@pur-phy> Date: 14 Jul 89 18:13:52 GMT References: <2751@ohstpy.mps.ohio-state.edu> <2360@pur-phy> Reply-To: murphy@newton.physics.purdue.edu.UUCP (William J. Murphy) Organization: Purdue Univ. Physics Dept., W. Lafayette, IN Lines: 44 In article <2360@pur-phy> hal@newton.physics.purdue.edu.UUCP (Hal Chambers) writes: >In article <2751@ohstpy.mps.ohio-state.edu> heff@ohstpy.mps.ohio-state.edu writes: >>. . . to write equations in source code such as >> a =: b + c; >> a := (b+c)/(d+e); >>as can be done in fortran. For that matter, are there any languages beside >>fortran which allow easy computation of complex numbers? > >Although Pascal (and Modula-2, etc.) allows the definition of a Complex >type, there is no way for the programmer to define the operators >other than as explicit procedure calls (functions can't return a >structured type). > >So the examples above would appear as something like: > > a =: b + c; > cadd(a, b,c); > > > a := (b+c)/(d+e); > cadd(c1, b,c); > cadd(c2, d,e); > cdiv(a, c1,c2); >Ugly!!!! This is one approach, another which works and is not quite so ugly is to create a memory pool for temporary calculation and use pointers into that pool. This way you can write TempPtr := cdiv( cadd(^b, ^c), cadd(^d, ^e) ); a.x := TempPtr^.x; a.y := TempPtr^.y; Don't flame the syntax, I haven't done this for a month at least. The point is that you can use pointers to the variable rather than passing a bunch of values and then you must be certain to reassign the values in the TempPtr into the original variable. The pool is treated as a circular buffer which has an arbitrary size (read big enough to fit your longest expression) I use a buffer of 150 double precision complex numbers. If you are interested in a copy of the Turbo-Pascal source that I have, send e-mail to me. I feel that it is too long to post on the net. Bill Murphy murphy@newton.physics.purdue.edu