diff --git a/kas.js b/kas.js index d5e6610..542e17d 100644 --- a/kas.js +++ b/kas.js @@ -2976,7 +2976,10 @@ _.extend(Pow.prototype, { print: function() { var base = this.base.print(); - if (this.base instanceof Seq || this.base instanceof Pow) { + if (this.base instanceof Seq || + this.base instanceof Pow || + this.base instanceof Rational && !this.base.isSimple() || + this.base instanceof Num && this.base.isNegative()) { base = "(" + base + ")"; } return base + "^(" + this.exp.print() + ")"; diff --git a/src/nodes.js b/src/nodes.js index 3bd3af4..0bf1d58 100644 --- a/src/nodes.js +++ b/src/nodes.js @@ -1443,7 +1443,10 @@ _.extend(Pow.prototype, { print: function() { var base = this.base.print(); - if (this.base instanceof Seq || this.base instanceof Pow) { + if (this.base instanceof Seq || + this.base instanceof Pow || + this.base instanceof Rational && !this.base.isSimple() || + this.base instanceof Num && this.base.isNegative()) { base = "(" + base + ")"; } return base + "^(" + this.exp.print() + ")"; diff --git a/test.html b/test.html index 6efcd03..0782d51 100644 --- a/test.html +++ b/test.html @@ -224,6 +224,8 @@

print(assert, "x^{a}", "x^(a)"); print(assert, "x^{ab}", "x^(a*b)"); + print(assert, "(2/5)^2", "(2/5)^(2)"); + print(assert, "(-3)^2", "(-3)^(2)"); }); QUnit.test("square root", function(assert) {