toString in case of Field Q - little error
Roemke opened this issue · comments
Hi and thanks for your work.
I experimented a little with polynomial.js and I think I find a small bug in toString.
In line 785f you use:
// Separate by +
if (str !== "" && val > 0) {
str += "+";
}
If I use
var pq=new Polynomial("3/4x^3+2/2x^2-1/3x+1/2");
$("#divOutput").append("pq: " + pq.toString() + "
");
all + signs are missing in the output.
I've analyzed the code not in deep, but a small try with
if (str !== "" && parseFloat(val) > 0) {
leads to the expected behaviour.
Karsten
Are you sure the plus signs are not chopped-off somewhere else? I tested your exact polynomial and the toString
method generates decimal numbers instead of fractions, but the plus-signs are correct: 0.75x^3+x^2-0.(3)x+0.5
Do you use the latest version of polynomial.js?
Hi Robert,
thanks for your answer and sorry, I copied the wrong part of my example code.
The problem arises, if I use the constructor which generate a polynom out of an array.
var coeffArrayQ = ["1/2","-1/3","2/2","3/4"]
var p1q=new Polynomial(coeffArrayQ);
$("#divOutput").append("p1q: " + p1q.toString() + "
");
I have appended my complete file, it uses polynomial, fraction and jquery for output.
Karsten
interneChecks2.zip
Thanks, that helped! Seems I missed to parse the values in an array. Version 1.2.0 just landed :) Thanks a lot for pointing this out!