Bug 3671 – x^^3 gives wrong result when x is a floating-point literal

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-01-04T03:30:00Z
Last change time
2015-06-09T01:27:14Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
bugzilla

Comments

Comment #0 by bugzilla — 2010-01-04T03:30:57Z
x^^3 evaluates to x^^2 when x is a floating-point literal. writeln(2.0^^3); // prints 4
Comment #1 by clugdbug — 2010-01-04T04:17:59Z
Ouch. I don't know what's happened here. The test suite I provided with the patch in bug 3577 doesn't compile! This quick patch fixes the immediate bug reported here, but it still doesn't compile the 3577 test suite. The culprit is the call to typeCombine(). The test needs to be performed before that. Index: expression.c =================================================================== --- expression.c (revision 324) +++ expression.c (working copy) @@ -9965,6 +9971,9 @@ ) && (e1->op == TOKint64 || e1->op == TOKfloat64) ) { + bool wantCube = (e2->op == TOKint64 && e2->toInteger() == 3) + || (e2->op == TOKfloat64 && e2->toReal() == 3.0); + typeCombine(sc); // Replace x^^2 with (tmp = x, tmp*tmp) // Replace x^^3 with (tmp = x, tmp*tmp*tmp) @@ -9973,8 +9982,8 @@ VarExp * ve = new VarExp(loc, tmp); Expression *ae = new DeclarationExp(loc, tmp); Expression *me = new MulExp(loc, ve, ve); - if ( (e2->op == TOKint64 && e2->toInteger() == 3) - || (e2->op == TOKfloat64 && e2->toReal() == 3.0)) + + if ( wantCube) me = new MulExp(loc, me, ve); e = new CommaExp(loc, ae, me); e = e->semantic(sc);
Comment #2 by bugzilla — 2010-01-11T22:01:23Z
Changeset 332
Comment #3 by bugzilla — 2010-01-30T22:46:39Z
fixed dmd 2.040