cln::divisors()
Ralf Stephan
ralf at ark.in-berlin.de
Mon Jun 21 18:16:05 CEST 2004
The complete factor() patch was sent to Richy.
Should the divisors be sorted?
Do we leave that to the client?
Can someone tell me why gcc barfs when I declare f const?
vector<cl_I> divisors(const cl_I& n)
{
cl_FEV f = factor(n);
vector<long> v(f.size());
vector<cl_I> res;
res.push_back(1);
while (true)
{
vector<long>::iterator vit = v.begin();
cl_FEV::iterator fit = f.begin();
while (*vit == (*fit)->exp)
{
*vit = 0;
if (++vit == v.end())
return res;
++fit;
}
cl_I prod = expt_pos((*fit)->fact, ++(*vit));
++vit;
++fit;
while (vit != v.end())
{
if (*vit > 0)
prod = prod * expt_pos((*fit)->fact, *vit);
++vit;
++fit;
}
res.push_back(prod);
}
}
ralf
More information about the GiNaC-devel
mailing list