cemyuksel / cyCodeBase

An open source programming resource intended for graphics programmers.
MIT License
271 stars 60 forks source link

Bug in PolynomialInflate? #28

Open lamont-granquist opened 7 months ago

lamont-granquist commented 7 months ago
template <int N, typename ftype> inline void PolynomialInflate( ftype infPoly[N+2], ftype const coef[N+1], ftype root )
{
    infPoly[N+1] = coef[N];
    for ( int i=N-1; i>=0; --i ) infPoly[i+1] = coef[i] - root*infPoly[i+1];
    infPoly[0] = -root*coef[0];
}

Should that be infPoly[i+1] = coef[i] - root * coef[i+1]?

Completely possible that I can't math or computer before caffeine this morning, but my C# version of that code isn't passing tests I wrote without that change and the fix makes sense in my head since it combines the lines before and after it, and the middle coefficients in the results are what I'm seeing being buggy.

cemyuksel commented 7 months ago

Nice catch! Yes, that is a bug, and, yes, your fix appears to be correct.