275 {
276
277 const double zero = 0.0;
278 double root = zero;
279 if (degree == 1) {
281 if (c[1] != zero) {
283 numRoots = 1;
284 }
285 else if (c[0] == zero) {
286 root = zero;
287 numRoots = 1;
288 }
289 else
290 numRoots = 0;
291
292 if (numRoots > 0 && tmin <= root && root <= tmax) {
293 roots[0] = root;
294 return 1;
295 }
296 return 0;
297 }
298
299
300
301
302
303
304
305 const int32_t derivDegree = degree - 1;
306 std::vector<double> derivCoeff(static_cast<size_t>(derivDegree) + 1);
307 std::vector<double> derivRoots(derivDegree);
308 for (
int32_t i = 0, ip1 = 1; i <= derivDegree; ++i, ++ip1) {
309 derivCoeff[i] =
c[ip1] * (double)(ip1) / (double)degree;
310 }
311 const int32_t numDerivRoots =
FindRecursive(degree - 1, &derivCoeff[0], tmin, tmax, maxIterations, &derivRoots[0]);
312
314 if (numDerivRoots > 0) {
315
316 if (
Find(degree, c, tmin, derivRoots[0], maxIterations, root))
317 roots[numRoots++] = root;
318
319
320 for (
int32_t i = 0, ip1 = 1; i <= numDerivRoots - 2; ++i, ++ip1) {
321 if (
Find(degree, c, derivRoots[i], derivRoots[ip1], maxIterations, root))
322 roots[numRoots++] = root;
323 }
324
325
326 if (
Find(degree, c, derivRoots[
static_cast<size_t>(numDerivRoots) - 1], tmax, maxIterations, root))
327 roots[numRoots++] = root;
328 }
329 else {
330
331 if (
Find(degree, c, tmin, tmax, maxIterations, root))
332 roots[numRoots++] = root;
333 }
334 return numRoots;
335 }
static int32_t Find(int32_t degree, const double *c, uint32_t maxIterations, double *roots)
Definition MeasureUtils.hpp:188