Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!helios.physics.utoronto.ca!alchemy.chem.utoronto.ca!mroussel From: mroussel@alchemy.chem.utoronto.ca (Marc Roussel) Newsgroups: comp.lang.misc Subject: Re: Fortran vs. C for numerical work Message-ID: <1990Dec5.185852.5191@alchemy.chem.utoronto.ca> Date: 5 Dec 90 18:58:52 GMT References: <16671@csli.Stanford.EDU> <1990Dec5.022302.25764@alchemy.chem.utoronto.ca> <16725@csli.Stanford.EDU> Organization: Department of Chemistry, University of Toronto Lines: 53 In article <16725@csli.Stanford.EDU> poser@csli.stanford.edu (Bill Poser) writes: >In article <1990Dec5.022302.25764@alchemy.chem.utoronto.ca> >mroussel@alchemy.chem.utoronto.ca (Marc Roussel) writes: >> >> Fortran has a relatively simple relation to mathematical formulae. >>You write the formula on paper and then transcribe it more or less >>directly into your program; > >How is C so different? Neither C nor Fortran has much direct math support. >Both have the basic operations in infix form. It's not just infix. Correct me if I'm wrong, but don't you have to declare every last variable in C? Given some relatively simple conventions and judicious use of implicit, you almost never have to declare a simple variable in Fortran. You also don't have to worry about which sqrt or log to use since the ANSI 77 standard. (Don't you have to do this in C? My impression was that C compilers, like F66 compilers, had to be told to use single precision functions here and double precision functions there.) >About the only things I can >thnk of are that the power function is not an operator in C and that >C does not have a complex type. Believe it or not, those are a concern to your typical scientific programmer. It's easy to write an inefficient power function; it's easier to let the compiler writer worry about that once. Since exponentiation is such a common operation, why should every programmer write his own? The same thing goes (doubly so!) for the complex type. If the language doesn't support it directly you wind up with a large number of mutually incompatible libraries for a set of operations used over and over again by everyone. >I've never found it at all difficult to >translate equations into C. The main difficulty is avoiding duplicate >computation, and that has to be done explicitly in Fortran too. It's not that it's difficult to simply "translate" an equation into C, it's that the code that has to be written around it is more elaborate. When I pass an array into a subroutine in Fortran, I can treat it exactly as I would in the calling routine. In C, I have to remember that I'm only getting a pointer and do appropriate arithmetic to extract the array elements. (Again, I'm more than willing to be corrected on this point.) Look, I'm sure you don't mind this sort of thing, but I do. I guess I just don't see why I should learn a new language when, by and large, I write ODE and algebraic equation solvers to which task Fortran's facilities (unlike C's) are ideally suited. C isn't a vegematic and I just get annoyed when someone tries to sell it to me as that. If you already know C, it probably isn't a big deal to use it for scientific computing. If you don't, why bother learning it until you run into a problem that doesn't fit Fortran's capabilities? Marc R. Roussel mroussel@alchemy.chem.utoronto.ca