From: utzoo!decvax!harpo!npoiv!npois!cbosgd!mark
Newsgroups: net.unix-wizards
Title: Re: Floating Point and Other Such Mysteries
Article-I.D.: cbosgd.2640
Posted: Mon Sep 20 12:38:23 1982
Received: Tue Sep 21 07:35:36 1982
References: rabbit.757

Be especially careful of cases like this:
	char foo();
	char a, b;
	double x, y;

	x = y * foo(a, b+1);

Some of the previous proposals would note that the assignment is done in
double, and so would calculate foo(a, b+1) in double.  Not only is it
wasteful (and inaccurate) to calculate b+1 in double, but since foo
is separately compiled and probably expects integer arguments, passing
it doubles and expecting a double back simply won't work.

You can't just look for the widest part of an expression, you have to
consider the pieces of it separately.  Another language that has to do
this kind of thing, depending on context, is Ada.  There was a long
controversy as people proposed cubic and quadratic algorithms to figure
out the types necessary for expression evaluation.  Finally somebody
came up with a clever linear algorithm, but the moral is clear: C is
supposed to be simple, and this kind of complexity does not belong in
the language.  If someone would (and could) guarantee to implement
	float a, b, c;
	a = b + c;
with single precision arithmetic, it would be possible to break down
hairier expressions into exactly what the author intends, without
lots of complex rules about context.

	Mark Horton