Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rochester!pt.cs.cmu.edu!ius2.cs.cmu.edu!edw From: edw@ius2.cs.cmu.edu (Eddie Wyatt) Newsgroups: comp.lang.c Subject: Re: Complex type ? Message-ID: <1148@ius2.cs.cmu.edu> Date: Wed, 6-May-87 19:55:30 EDT Article-I.D.: ius2.1148 Posted: Wed May 6 19:55:30 1987 Date-Received: Sat, 9-May-87 01:31:47 EDT References: <7264@brl-adm.ARPA> Organization: Carnegie-Mellon University, CS/RI Lines: 71 In article <7264@brl-adm.ARPA>, lyle@ads.arpa (Lyle Bacon) writes: > > C is an evolving language. I will make a possibly sacrilegious > suggestion that the type "complex" be incorporated. After all, such a > type is now a part of LISP (Common). > > The purest says:" Well, one can just define a structure complex." > > (Many years ago I was discussing with a friend the relative > utility of FORTRAN and ALGOL for numerical work. I mentioned that > ALGOL did not have a type COMPLEX. He said, "Well you can just write > a little procedure.") > > However, the resultant code form using structures and func- > tions is much less readable and harder to check. (I have enough > trouble with "pow (x,y)" compared with x**y.) > > ... > > struct complex > { > double re; > double im; > }; > > > { > ... > > struct complex complex_mult(); > > struct complex A, B, C; > struct complex P; > > P = complex_mult(A, complex_mult(B, C)); > > ... > > } > > One could use a shorter form, such as "cm()" instead of > "complex_mult()", but that doesn't really get to the point. > > P = A * B * C; > > is more easily read and checked. > > (I am new to "info-c; perhaps this topic has come up before.) Sounds like you should be programming in ADA or some other data abstract language. If you want to add a new type to the language, just make a package for it and defined the operators on it. I do believe that you are allowed to define *+-... over other data types and still use the infix notation (don't take my word for it through, I'm not a ADA hacker). One problem with adding a new data type (or any new feature) to any language is, one must determine how the new feature could interact with existing features and defined the semantics of this new feature with respects to every other feature. Example with the complex type: int x; complex y,z; y = x + z; Is it legal? -- Eddie Wyatt e-mail: edw@ius2.cs.cmu.edu