Order of evaluation, machine floating point

Henry Spencer henry at utzoo.UUCP
Tue Mar 17 08:20:49 AEST 1987

> ... for unknown reasons all floating arithmetic is supposed to occur in
> double precision.  I realize that K&R said it, but I don't know why...

Dennis Ritchie answered this on the net a long time ago:

> From decvax!harpo!npoiv!alice!research!dmr Wed Sep  8 23:22:25 1982
> Subject: float/double in C
> Newsgroups: net.unix-wizards
> Several people have correctly quoted the manual as calling for evaluation
> of expressions on (single-precision) floats in double precision.  The
> rule was made for 3 reasons.
> 1) To make certain that floating-point function arguments and return values
>    were always double (thus avoiding multiple library routines and constant
>    need for casts.)
> 2) Because the PDP-11 makes it horribly difficult to mix modes otherwise
>    (yes, I admit it).
> 3) Because it is numerically more desirable to evaluate single-precision
>    expressions in double precision, then truncate the result.
> These are in order of importance...

Religious use of X3J11 function prototypes will pretty much solve Dennis's
#1 problem, #2 is increasingly a dead issue, and #3 is usually true for the
naive but makes the pros very unhappy.
"We must choose: the stars or	Henry Spencer @ U of Toronto Zoology
the dust.  Which shall it be?"	{allegra,ihnp4,decvax,pyramid}!utzoo!henry

More information about the Comp.lang.c mailing list