[Issue 3481] PATCH: opPow(), x ^^ y as a power operator

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 6 13:48:52 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3481



--- Comment #3 from Don <clugdbug at yahoo.com.au> 2009-11-06 13:48:51 PST ---
(In reply to comment #1)
> I've been wanting an exponentiation operator since the Stone Age, but it seemed
> like too small an issue to really make a point about.  This is terrific. 
> However, can we at least consider making ^ the exponentiation op and moving xor
> to ^^?  Yes, it breaks C compatibility, but who the heck really uses bitwise
> xor except in really low-level code anyhow?

That's not possible, because things like int y  = x ^ 2; would continue to
compile, but silently change meaning. x ^^ y causes no problems, because it
never had a meaning. I agree it's unfortunate that C grabbed the best symbols
and used them for some relatively obscure operations (~ is a classic example)
-- but it's too late now. I actually think we're lucky that ^^ is available.

(In reply to comment #2)
> Sweet. Suggestion: rewrite x^^=y into powAssign(x, y) and define powAssign
> appropriately, e.g.:
> 
> ref B powAssign(B, E)(ref B b, E e) if (isNumeric!B && isNumeric!E);
> 
> That way you don't need any trick to evaluate x only once etc.

It's not really a big problem to do the whole thing properly. I just
implemented the bare minimum to get started. Really, it should support constant
folding, and generate back-end code for squaring, etc. That's not technically
difficult, but it involves changes to many different bits of code in the
compiler, which makes it a difficult patch for Walter to evaluate and integrate
(and hence, less likely to be accepted).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list