nicolewhite/algebra.js

Coefficients on variables with degree > 1 do not parse correctly

nicolewhite opened this issue · 5 comments

This is in reference to #37.

algebra.parse("3/2x^2").toString();
"9/4x^2"
algebra.parse("(3/2)x^2").toString();
"9/4x^2"
algebra.parse("(3/2) * x^2").toString();
"9/4x^2"

Looks like the degree is being applied to the coefficient.

algebra.parse("(3/2) * x^3").toString();
"27/8x^3"

This also affects integers.

algebra.parse("2 * x^3").toString();
"8x^3"

That's weird...I wrote a test for "(3/2) * x^2" and got the correct result.
When I parse the same input on http://algebra.js.org/ it returns "9/4x^2".

Oops! Maybe I didn't update the version available on gh-pages.

Ok, that mystery is solved 😄
I already found the section in the parser that causes the bug: It's a problem with the missing 'multiply' operator. I should be able to fix it.

Ok. My bad. This is now the behavior I'm seeing:

algebra.parse("3/2x^2").toString()
"9/4x^2"
algebra.parse("3/2*x^2").toString()
"3/2x^2"

But this is how it is documented, so I wouldn't call the former example a bug. In the docs I state "You must use the * operator between coefficients and variables."

You can remove the line from the docs, I fixed it.