Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!tut.cis.ohio-state.edu!unmvax!ariel.unm.edu!ghostwheel.unm.edu!john From: john@ghostwheel.unm.edu (John Prentice) Newsgroups: comp.lang.fortran Subject: Re: Highly Optimizable Subset of C (was: Fortran vs. C for numerical work) Message-ID: <1990Nov25.081657.3087@ariel.unm.edu> Date: 25 Nov 90 08:16:57 GMT References: <1990Nov22.051446.1871@ccu.umanitoba.ca> <1990Nov23.181209.26366@zoo.toronto.edu> <1990Nov24.201731.3442@cunixf.cc.columbia.edu> <14568@smoke.brl.mil> Sender: news@ariel.unm.edu (USENET News System) Organization: University of New Mexico Math Dept., Albuquerque, NM Lines: 78 Newsgroups: comp.lang.fortran Subject: Re: Highly Optimizable Subset of C (was: Fortran vs. C for numerical work) References: <1990Nov22.051446.1871@ccu.umanitoba.ca> <1990Nov23.181209.26366@zoo.toronto.edu> <1990Nov24.201731.3442@cunixf.cc.columbia.edu> <14568@smoke.brl.mil> Organization: Amparo Corporation, Albuquerque, NM In article <14568@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: > >It doesn't matter whether that is true or not; such crippled programming >would negate much of the advantage of using C in the first place. Use >the right tool for the job and stop worrying about code optimization! That is all well and good if you code only takes seconds to run. Try ignoring optimization in a code that runs hundreds of hours! Here is a question for all the C people out there. The following is a simple Fortran code to compute the roots of a complex quadratic equation. It is written in ANSI Fortran 77 and will run on any Fortran compiler that conforms to the Fortran 77 standard. program root c c solve a*z**2 + b*z + c = 0 for complex a,b,c,z c real zero,one,two,three,four,five parameter (zero=0.0,one=1.0,two=2.0,three=3.0,four=4.0, * five=5.0) complex a,b,c,root1,root2,disc,sqrt1 c c hard-wire in a,b,c to make it simple c a=(one,zero) b=(-three,two) c=(five,-one) c c calculate the discriminant c disc=b**2-cmplx(four)*a*c c c calculate the upper half plane square root of the c discriminant c sqrt1=sqrt(disc) c c now calculate the roots c root1=(-b+sqrt1)/(cmplx(two)*a) root2=(-b-sqrt1)/(cmplx(two)*a) c c print out result c write (*,'('' the roots are: '',1p2e15.5/16x,1p2e15.5)') root1, * root2 c end I now challenge C programmers to write an equivalent C code, using only ANSI C features so that it will run using any ANSI C compiler. I am willing to bet that the Fortran code is much smaller and simplier. I could easily have made this code even simplier by eliminating all the cmplx() function calls which are not actually necessary. Now, this is a typical, if somewhat trivial, example of what people use Fortran for. So what is missing here that C provides me? This is exactly my point, Fortran works just fine for most things scientists do, at least so far as numerical computation. It isn't until you stray away from numerical computation that C becomes useful (bit manipulation for example is much better done in C than Fortran). In fact, I still would maintain that Fortran is an easier language to learn and use for numerical computation, as my example is intended to demonstrate. John Prentice Amparo Corporation Albuquerque, NM john@unmfys.unm.edu