Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!purdue!i.cc.purdue.edu!j.cc.purdue.edu!k.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.lang.c Subject: Re: Power operator? Message-ID: <658@l.cc.purdue.edu> Date: 18 Jan 88 21:39:52 GMT References: <6982@brl-smoke.ARPA> <326@splut.UUCP> <327@splut.UUCP> <4186@eagle.ukc.ac.uk> Organization: Purdue University Statistics Department Lines: 66 Summary: FORTRAN is worse than C for good mathematical routines In article <4186@eagle.ukc.ac.uk>, has@eagle.ukc.ac.uk (H.A.Shaw) writes: > This may look like a flame. It is not supposed to be, but I feel strongly > that we are wasting our time with questions that have no relavence to C as a > language. I have left out much of the original article. I hope I have not omitted anything important. > What people appear to be forgetting is what C is for. > You should not do complex mathematical work in C, > If you want maths, use FORTRAN, I find that I can do much better mathematical programming in C than in FORTRAN. By better programming, I mean that I can use constructs in C which are convenient and produce efficient code, and which FORTRAN does not know the first thing about. The only advantages of FORTRAN are the power operator and multi-dimensional arrays. The major disadvantages are the lack of indirection and casting, and the requirement that a function has an argument. Also C lets you use the rest of the instruction set (although it makes it difficult, sometimes very difficult). > 1) The programmer knows what he is doing and it is none > of the language's business to try and stop him. That is exactly what I am getting at. This is why C should attempt to be a flexible language, and if the programmer wants to use a useful construct, the language should at least allow it. > 2) Just because you *MAY* do something does not mean > mean that you *SHOULD* do it. Who decides what should be done? From comment 1), it must be the programmer! Therefore let the programmer do it! > I was told to think of C as a macro-assemblier for the hardware you are on. Then let that be done; that is what I want and do not find. > C is one of very few languages that has direct access to the addressing modes > of the underlieing machine. And this is not important in numerical analysis? > I wholeheartedly agree, and hope I write better C programs now for > three years of BASIC/PASCAL/FORTRAN/FORTH first. What would enable one to do a good programming job is to understand the machine first, so that one can know when the language is inadequate. I will modify my algorithm if the machine architecture calls for it. In a flexible language, most of the modifications can be indicated by comments. An example of an algorithm which should never have been programmed in C, and which should have been inline, is the infamous 4.2BSD frexp. That a construct is machine independent does not mean that its implementation should be. Actually, the power operator would be nearly machine independent; the major implementation differences would be where to stop treating special case of small integer exponents. In case you think that C++ should be used for some of these things, the answer is frequently _no_! If C++ were produced anew, it _might_ do a fair job. However, since it is a C preprocessor, whenever C produces bad code, it is likely to do worse. The language should help the programmer who knows the problem and the machine. -- Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907 Phone: (317)494-6054 hrubin@l.cc.purdue.edu (ARPA or UUCP) or hrubin@purccvm.bitnet