continueing on polynomials, fix of NRVec unary minus

This commit is contained in:
2021-06-10 17:44:54 +02:00
parent e8ca6b583e
commit 30861fdac6
5 changed files with 132 additions and 16 deletions

View File

@@ -23,19 +23,49 @@
namespace LA {
template <typename T>
void Polynomial<T>::polydiv(const Polynomial &rhs, Polynomial &q, Polynomial &r) const
{
if(rhs[rhs.degree()]==0) laerror("division by a polynomial with zero leading coefficient - simplify it first");
if(rhs.degree()==0) //scalar division
{
q= *this/rhs[0];
r.resize(0,false);
r[0]=0;
return;
}
int rdegree= rhs.degree();
int qdegree= degree()-rdegree;
if(qdegree<0)
{
q.resize(0,false);
q[0]=0;
r= *this;
return;
}
//general case
q.resize(qdegree,false);
r= *this; r.copyonwrite();
for(int i=degree(); i>=rdegree; --i)
{
T tmp= r[i]/rhs[rdegree];
q[i-rdegree]= tmp;
r -= rhs.shifted(i-rdegree)*tmp;
}
r.resize(rhs.degree()-1,true);
}
/***************************************************************************//**
* forced instantization in the corresponding object file
******************************************************************************/
template class Polynomial<int>;
template class Polynomial<float>;
template class Polynomial<double>;
template class Polynomial<std::complex<double> >;
#define INSTANTIZE(T) \
//INSTANTIZE(float)
//INSTANTIZE(double)