FlorisSteenkamp / FloPoly

A practical, root-focused JavaScript polynomial utility library.
3 stars 2 forks source link

Bug in the `reflectAboutYAxis` function #10

Open tanguymagne opened 1 month ago

tanguymagne commented 1 month ago

The reflectAboutYAxis function works only for polynomials of even degree.

Indeed, because the polynomial is given as an array from highest to lowest power, if the polynomial has an even degree, the odd coefficients are negated, but if the polynomial has an odd degree, then the even coefficients are negated which is not correct.

One fix is to replace line 23 with if (i % 2 === (d - 1) % 2).

FlorisSteenkamp commented 1 month ago

Thanks!

The tests didn't look at polynomials of odd degree.

Fixed and added tests - new npm version is 6.0.9.