C Floating point arithmetic

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Tue Nov 26 01:47:33 AEST 1985


> >No -- on most machines, single-precision does not offer enough significance
> >for serious number-crunching, so people tend to use double-precision
> >anyway if they care about the results.
> 
> Now, this is a most disingenious argument.  If this were really true, one
> would map 'float' to the double-precision operations and totally ignore the
> single-precision ones.
> 
> Let's face it - this, as well as several other "features" of the Unix system
> (such as the treatment of parameters passed to functions) is left over from
> the PDP-11 days, and puts the lie to Unix's claim of machine independance...

Both viewpoints have some merit.  By the way, the discussion is
about C, not about UNIX!!  Certainly, some of C's harder-to-
justify features, such as parameter widening, are the result
of implementing the original version on a PDP-11.  But these
rules can be and are expressed in a machine-independent manner.
Just because a language does not offer complete access to every
quirk of every architecture does not mean that the language is
machine-dependent!

If C were to be redesigned, it would probably be wise to give
EVERY basic data type equal citizenship.  But it's too late now.

Actually, X3J11 allows floats to be operated on without widening
to doubles (except for parameter passing).  Due to the unique
characteristics of floating-point operations, this change is
unlikely to break much existing correct code (unlike changes to
integer data types).

I agree that in most cases where the loss of speed might really
matter, double precision is usually needed anyway to get
meaningful results.  Some people, though, judge code more on how
fast it runs than on whether it performs a useful function
correctly.



More information about the Comp.lang.c mailing list