[Issue 3481] New: PATCH: opPow(), x ^^ y as a power operator
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Nov 6 13:03:02 PST 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3481
Summary: PATCH: opPow(), x ^^ y as a power operator
Product: D
Version: 2.036
Platform: Other
OS/Version: All
Status: NEW
Keywords: patch
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: clugdbug at yahoo.com.au
--- Comment #0 from Don <clugdbug at yahoo.com.au> 2009-11-06 13:03:01 PST ---
Created an attachment (id=492)
Patch against DMD2 svn 241
Requests for an exponential operator have come up numerous times on the
newsgroup.
This patch introduces a new binary operator ^^ which performs exponentiation:
x ^^ y is pow(x, y).
Likewise x ^^= y is x = pow(x, y).
The corresponding overloaded operators are opPow, opPow_r, and opPowAssign.
In the patch, ^^ is supported for integral and floating-point types.
Two special cases are supported:
x ^^ 1 becomes x;
x ^^ 0.5 becomes sqrt(x);
x ^^ y becomes pow(x, y);
This requires pow() and/or sqrt() to be defined, typically by importing
std.math.
IE, this is just syntax sugar.
BUGS: I'm translating x^^=y into x = pow(x, y). This means x gets evaluated
twice.
If this patch is accepted, there is much that can be done with the
implementation.
Most importantly by adding back-end support for x ^^ 2.
However, this simple implementation would give us the semantics.
--
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