From 7083541632377945508
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,9a6b7da9ba54eaea
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1993-07-05 11:09:35 PST
Path: gmd.de!xlink.net!howland.reston.ans.net!darwin.sura.net!udel!princeton!allegra!alice!ark
From: ark@alice.att.com (Andrew Koenig)
Newsgroups: comp.std.c++
Subject: Re: C++ Language Extensions
Message-ID: <25936@alice.att.com>
Date: 5 Jul 93 16:09:41 GMT
Article-I.D.: alice.25936
References: <C9Js78.E7F@jabba.ess.harris.com> <212tii$5nb@senator-bedfellow.MIT.EDU> <rfgC9KttA.AKq@netcom.com> <215t2r$sv4@senator-bedfellow.MIT.EDU>
Reply-To: ark@alice.UUCP ()
Organization: AT&T Bell Laboratories, Murray Hill NJ
Lines: 40

In article <215t2r$sv4@senator-bedfellow.MIT.EDU> jfc@athena.mit.edu (John F Carr) writes:

> Exponentiation is a very small addition to a compiler.

I wish that were true.  It is a very small addition to a parser, but
there is a *lot* of other work to do.

For example, what should the language guarantee about accuracy?
If x is a floating-point value, it should presumably be guaranteed
that x~2 (I'll use ~ for exponentiation in this note) is equal to
x*x.  But what about x~3?  Should that be required to be equal to
x*x*x?  Or should x~3 be required to be the closest possible approximation
to x cubed?  The two are not necessarily the same, because x*x*x is
not the most accurate possible way of cubing x.

Either way you do it, you lose in some cases.  For example, if x~3
is not required to be equal to x*x*x, then an optimizer can't rewrite
x~3+3*x~2 as x*x*(x+3).  On the other hand, if x~3 IS required to be
equal to x*x*x, then x~3 won't be equal to pow(x,3), assuming a
careful implementation of pow that always returns the most accurate
result possible.

This problem becomes even worse for 4th powers, because x~4 might be
evaluated as ((x*x)*(x*x)) or x*(x*x*x), neither of which is guaranteed
to produce the most accurate possible result.  That means there are at
least three legitimate values for x~4; which one should we pick?

Finally, one might argue that x~2 should be equivalent to x*x even
if x is of user-defined type -- so long as x*x is well-defined and
~ isn't explicitly overridden.  That is, of course, the most straightforward
way of obtaining sensible results of x is, say, of class Complex.
But now we have the possibility that user-defined * isn't even
associative, let alone commutative.  How much implementation latitude
should be allowed?  And so on.

I'm not claiming these questions don't have answers, but I shudder to
think how much committee time it would take to answer them.
-- 
				--Andrew Koenig
				  ark@research.att.com


