Why I use C instead of fortran

Tom Stockfisch ix426 at sdcc6.ucsd.EDU
Wed Feb 3 08:35:44 AEST 1988


In article <257 at tolsun.oulu.fi> jto at tolsun.UUCP (Jarkko Oikarinen) writes:
>(Just forwarding this message...)
>
>In article <3597 at sdcc6.ucsd.EDU> (Tom Stockfisch) (that's ME) writes:
>>In C you can write interactive programs
>>in which you input complex commands which are then parsed and
>>executed. In fortran you write programs which just prompt
>>you to input x and y and then follow a fixed regimen. ...

>Which command(s) FORTRAN is(are) missing that make interactive 
>programs impossibility? 

Data processing is hard in Fortran.  Of course, it's not impossible, it's
just much more convenient to do it in C.  You can't use lex(1) or yacc(1)
with fortran (yes, I know you can use ratfor with lex).  Have you ever
written a symbol table package in fortran (with install() and lookup())?
It is very messy without a "struct" facility.  Besides which, in fortran
you have to hard code the size of the table, since there is no
dynamic memory allocation possible.

>For serious number-crunching I think FORTRAN is superior to C.
> 1) COMPLEX variables: Write complex arcus hyperbolic tangent in C!

As I believe I said in my posting, I use fortran for complex arithmetic.
I still write main() and all i/o stuff in C, and use fortran
subroutines only where the complex arithmetic occurs.  As soon as
C++ becomes widely available, I won't use fortran at all.  The former's
complex number facility is far superior to fortran.  For example,
I can redefine complex division if I think the one provided is too
slow or not numerically stable enough.

> 2) single precision: all (ALL) real math is performed in double
>      precision in C.

All C compilers I have worked with have an option to disable
automatic float-double conversion and allow single precision arithmetic.
This common extension is even blessed (required?) in proposed ANSI C.

>      Transcendental functions require
>      far more (double) multiplications than single versions.

Only if you have an algorithm with slow (e.g. linear) convergence.
If you are summing a series, and c[i] is something like (1/i!), then
there might be very little difference in the number of terms required
for single vs. double precision.  Especially if you have performed an
argument reduction step so that x is between, say, 0 and 0.5.
If you have an algorithm with quadratic convergence, such as newton
raphson, it takes only one extra iteration to turn single precision
into double.

>        Jouko Holopainen
-- 

||  Tom Stockfisch, UCSD Chemistry   tps at chem.ucsd.edu



More information about the Comp.lang.c mailing list