Path: utzoo!utgpu!water!watmath!clyde!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Power proposal for ANSI C Keywords: power exponentiation ** Message-ID: <2252@haddock.ISC.COM> Date: 14 Jan 88 00:56:49 GMT References: <38384@sun.uucp> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 44 In article <38384@sun.uucp> dgh%dgh@Sun.COM (David Hough) writes: >Comment #9, Section 3.3.4: add power operator for integral exponents As you said, ANSI can pick whatever syntax they want; but to avoid ambiguity Let's use "*^" when we're just arguing semantics. I've edited the quoted material accordingly. >To best correspond to the usage of mathematics and other computer languages, >the precedence of *^ must be greater than that of a multiplicative or >additive operator. If this were the only criterion, I'd say it should be put into a new precedence class between unary and multiplicative. However, this makes -x*^2 mean the "wrong" thing. If this is a problem (apparently bc users don't mind), my recommendation is to give it a precedence between postfix unary and prefix unary. (Note that "->id", ".id", "[expr]", and "(arglist)" can all be considered postfix unary, just as "(type)" can be considered prefix unary.) More precisely: power-expression: postfix-expression postfix-expression *^ cast-expression unary-expression: power-expression ++ unary-expression -- unary-expression unary-operator cast-expression sizeof unary-expression sizeof ( type-name ) (Also, "*^=" should be added to the list of assignment operators.) >Note that unlike other operators, the "usual arithmetic conversions" are not >made to b and n; the type of the result is always that of b. I'd like to mention that there is already a precedent: 1<<1L is 2, not 2L. >If n < 0, then the result is the reciprocal of b *^ (-n), which is 0 if b is >an integral expression >= 2. I think 2 *^ -1 should be undefined (as is 1 << -1), rather than zero. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint