[Issue 3577] Wrong precedence for opPow
https://issues.dlang.org/show_bug.cgi?id=3577 Andrei Alexandrescu and...@erdani.com changed: What|Removed |Added Version|future |D2 --
[Issue 3577] Wrong precedence for opPow
http://d.puremagic.com/issues/show_bug.cgi?id=3577 Walter Bright bugzi...@digitalmars.com changed: What|Removed |Added Status|NEW |RESOLVED CC||bugzi...@digitalmars.com Resolution||FIXED --- Comment #5 from Walter Bright bugzi...@digitalmars.com 2009-12-31 11:20:41 PST --- Fixed dmd 2.038 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 3577] Wrong precedence for opPow
http://d.puremagic.com/issues/show_bug.cgi?id=3577 --- Comment #4 from Don clugd...@yahoo.com.au 2009-12-21 15:36:28 PST --- TEST CASES FOR TEST SUITE (Note: doesn't include any of the runtime tests) - // Tests for ^^ // TODO: These tests should not require import std.math. import std.math; // Test float ^^ int static assert( 27.0 ^^ 5 == 27.0 * 27.0 * 27.0 * 27.0 * 27.0); // Check the typing rules. static assert( is (typeof(2.0^^7) == double)); static assert( is (typeof(7^^3) == int)); static assert( is (typeof(7L^^3) == long)); static assert( is (typeof(7^^3L) == long)); enum short POW_SHORT_1=3; enum short POW_SHORT_3=7; static assert( is (typeof(POW_SHORT_1 * POW_SHORT_1) == typeof(POW_SHORT_1*POW_SHORT_1))); static assert( is (typeof(7.0^^3) == double)); static assert( is (typeof(7.0L^^3) == real)); static assert( is (typeof(7.0f^^3) == float)); static assert( is (typeof(POW_SHORT_1^^3.1) == double)); static assert( is (typeof(POW_SHORT_1^^3.1f) == float)); static assert( is (typeof(2.1f ^^ POW_SHORT_1) == float)); static assert( is (typeof(7.0f^^3.1) == double)); static assert( is (typeof(7.0^^3.1f) == double)); static assert( is (typeof(7.0f^^3.1f) == float)); static assert( is (typeof(7.0f^^3.1L) == real)); static assert( is (typeof(7.0L^^3.1f) == real)); // Check typing for special cases static assert( is (typeof(7.0f^^2) == float)); static assert( is (typeof(7.0f^^1.0) == double)); static assert( is (typeof(1^^0.5f) == float)); static assert( is (typeof(7^^0.5f) == float)); static assert( is (typeof(3L^^0.5) == double)); static assert(POW_SHORT_1 ^^ 2 == 9); static assert(4.0 ^^ POW_SHORT_1 == 4.0*4.0*4.0); // ^^ has higher precedence than multiply static assert( 2 * 2 ^^ 3 + 1 == 17); static assert( 2 ^^ 3 * 2 + 1 == 17); // ^^ has higher precedence than negate static assert( -2 ^^ 3 * 2 - 1 == -17); // ^^ is right associative static assert( 2 ^^ 3 ^^ 2 == 2 ^^ 9); static assert( 2.0 ^^ -3 ^^ 2 == 2.0 ^^ -9); // 1 ^^ n is always 1, even if n is negative static assert( 1 ^^ -5 == 1); // -1 ^^ n gets transformed into n 1 ? -1 : 1 // even if n is negative static assert( (-1) ^^ -5 == -1); static assert( (-1) ^^ -4 == 1); static assert( (-1) ^^ 0 == 1); // Other integers raised to negative powers create an error static assert( !is(typeof(2 ^^ -5))); static assert( !is(typeof((-2) ^^ -4))); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 3577] Wrong precedence for opPow
http://d.puremagic.com/issues/show_bug.cgi?id=3577 Don clugd...@yahoo.com.au changed: What|Removed |Added CC||clugd...@yahoo.com.au --- Comment #1 from Don clugd...@yahoo.com.au 2009-12-05 11:31:16 PST --- PATCH: To give it higher precedence than *, but lower than unary operators, so that both of the examples return 17, just create a parsePowExp() function in parse.c. Expression *Parser::parseMulExp() { Expression *e; Expression *e2; Loc loc = this-loc; e = parsePowExp(); while (1) { switch (token.value) { case TOKmul: nextToken(); e2 = parsePowExp(); e = new MulExp(loc,e,e2); continue; case TOKdiv: nextToken(); e2 = parsePowExp(); e = new DivExp(loc,e,e2); continue; case TOKmod: nextToken(); e2 = parsePowExp(); e = new ModExp(loc,e,e2); continue; default: break; } break; } return e; } Expression *Parser::parsePowExp() { Expression *e; Expression *e2; Loc loc = this-loc; e = parseUnaryExp(); while (1) { switch (token.value) { case TOKpow: nextToken(); e2 = parseUnaryExp(); e = new PowExp(loc,e,e2); continue; default: break; } break; } return e; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 3577] Wrong precedence for opPow
http://d.puremagic.com/issues/show_bug.cgi?id=3577 --- Comment #2 from Don clugd...@yahoo.com.au 2009-12-05 12:56:29 PST --- To make it right-associative, change the key line in parsePowExp into: --- case TOKpow: nextToken(); e2 = parsePowExp(); e = new PowExp(loc,e,e2); continue; -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---