C vs. FORTRAN

Richard A. O'Keefe ok at quintus.uucp
Wed Jun 29 04:44:39 AEST 1988


In article <19633 at watmath.waterloo.edu> rwwetmore at watmath.waterloo.edu (Ross Wetmore) writes:
>  In C exponentiation is not an operator, but rather a function.
>I have seen C programs where a for-loop has been used to avoid
>doing a pow() function call or because simple integer exponentiation 
>doesn't really exist. A Fortran programmer doesn't really think
>and just uses '**' which usually just gets translated into an
>appropriate function call by the compiler.

Not to knock either C or Fortran, but this may be a case where C is better
to use than Fortran.  Just because ** _looks_ like a simple operation (not
that different from *) doesn't mean that it isn't a call to a costly function.
I have seen published Fortran code where polynomials were evaluated with an
O(N * log(N)) algorithm (N being the degree of the polynomial) instead of an
O(N) algorithm, presumably because the programmer thought ** must be cheap.
If you have a program calculating X**N where N is an integer but is not in
the range -2..+3, take a very careful look at your program to see how it can
be improved.



More information about the Comp.lang.c mailing list