C for Numerical Programming

utzoo!decvax!harpo!floyd!cmcl2!mcbryan utzoo!decvax!harpo!floyd!cmcl2!mcbryan
Thu Oct 28 10:48:54 AEST 1982

			C for Numerical Programming

With one or two very small exceptions (lack of exponent operator,
complex type) C is a far better language than FORTRAN for numerical work.
The principal point is that FORTRAN has no data structures except
rectangular arrays.   C Structures (and now classes ?) provide a very
rich tool for a numerical analyst.   Similarly for pointers.   Every
large numerical code I know of does storage allocation - in FORTRAN
that means integer 'pointers'!  FORTRAN is essentially assembler level 
as far as data structures.    Many modern numerical programs involve
non-rectangular array data-structures (tree-structered refined grids,
graph representations of sparse matrices,....) - in FORTRAN those
become unreadable and impossible to debug.

I can think of NO reasons not to use C as a numerical language (other than
the annoying fact that all arithmetic is double precision).
There are MANY reasons not to use FORTRAN.   There is no difficulty 
calling FORTRAN library routines from C - I routinely use packages such

I have written , as an experiment, a fair amount of numerical code in ADA 
which is very nice.    However C appeals to me for the same reasons it 
does to C system people - it is concise, powerful, the typing is not always 
in your way, and you can get decent code generated when you need to get close
to the machine.    Of course by C I mean C+lint - without lint you
have would be in big trouble with 50,000 line C codes ( the size of
my typical codes).    Pascal has all the usual problems of pascal!

Among other things, I teach graduate level Numerical Analysis and Computer
Graphics courses.   I encourage students to program in the language they
feel most comfortable with.   You would be astonished how few FORTRAN
assignments are turned in, while C is surprisingly common.   The quality
of the FORTRAN assignments/projects is generally inferior - its a 
question of productivity (students have limited time to get things done).

Here at NYU, we have a group of about 12 faculty, post-docs and students
doing very serious numerical analysis in C.    (I am currently running
a 12 Mb program which has accumalated 33 hours of CPU time on a Vax 780).

I would appreciate hearing from others who use C for numerical work.

My wish list for numerical C is very short:

1. Add a -F flag to cc to generate single-precision instructions for
	expressions that use only floats.  (in many compilers  the
	-F might do nothing).   This effectively redefines the
	double precision accuracy to be 32 rather than 64 bit, and
	thought of this way does not redefine the language.

2. Improve the math library routines (this is actually being done right
	now at Berkeley).

3. Add complex type with arithmetic operators supported (preferably not 
	via preprocessor).  

				Oliver McBryan,
				Courant Institute,
				New York University.

More information about the Comp.lang.c mailing list