36 #if (defined _MSC_VER && _MSC_VER < 1800) 37 #pragma WARNING("This compiler does not support the functions ilogb and scalbln.") 63 xdata = { 0.0, DBL_MAX, DBL_MIN_EXP, DBL_MAX_EXP };
68 #define xbits(z) DBL_MANT_DIG 69 #define xeta(z) DBL_EPSILON 71 z->real(scalbln(z->real(), e));
72 z->imag(scalbln(z->imag(), e));
80 xreal x, xm, f, dx, df;
83 for(
int i = 0; i<=deg; i++){ tmp[i] =
xabs(P[i]); };
87 if(tmp[deg - 1] != 0.0) {
89 xm = tmp[deg] / tmp[deg-1];
100 for(
int i = 1; i <= deg; i++)
109 while(fabs(dx / x) > 0.005) {
112 for(
int i = 1; i <= deg; i++){
135 int hi, lo, max, min, x, sc;
138 hi = (int)(
xdata.MAX_EXP / 2.0);
143 for(
int i = 0; i <= deg; i++) {
144 if (P[i] !=
xdata.ZERO){
152 if(min >= lo && max <= hi)
return;
159 if(
xdata.MAX_EXP - sc > max) sc = 0;
163 for(
int i = 0; i<= deg; i++){
xscalbln(&P[i],sc); }
178 for (i = 0; i < deg; i++) {
189 for(i = 0; i < deg; i++)
190 H[i] = (P[i] * (deg-i)) / deg;
193 for(jj = 1; jj <= l1; jj++) {
195 t = -P[deg] / H[deg-1];
196 for(i = 0; i < deg-1; i++){
198 H[j] = t * H[j-1] + P[j];
203 for(i = 0; i < deg-1; i++) {
217 for(
int i = 1; i <= deg; i++){ q[i] = q[i-1] * s + Q[i]; };
226 Hs =
polyev(deg-1, s, H, h);
239 for(
int j = 1; j < deg; j++)
240 H[j] = t * h[j-1] + p[j];
245 for(
int j = 1; j < deg; j++)
261 for(
int i = 0; i <= deg; i++)
262 e = e * ms +
xabs(p[i]);
264 return e * (
xeta(p[0]) + MRE) - MRE * mp;
277 xreal mp, ms, omp = 0.0, relstp = 0.0, tp;
283 for(i = 1; i <= l3; i++) {
285 Ps =
polyev(deg, *s, P, p);
288 if(mp <= 20 *
errev(deg, p, ms, mp)) {
297 if(!(b || mp < omp || relstp >= 0.05)){
303 if(relstp <
xeta(P[0])) tp =
xeta(P[0]);
307 Ps =
polyev(deg, *s, P, p);
308 for(j = 1; j <= 5; j++){
309 t =
calct(&bol, deg, Ps, H, h, *s);
310 nexth(bol, deg, t, H, h, p);
317 if(mp * 0.1 > omp)
return conv;
323 _20: t =
calct(&bol, deg, Ps, H, h, *s);
324 nexth(bol, deg, t, H, h, p);
325 t =
calct(&bol, deg, Ps, H, h, *s);
348 Ps =
polyev(deg, *s, P, p);
353 t =
calct(&bol, deg, Ps, H, h, *s);
356 for(
int j = 1; j <= l2; j++){
360 nexth(bol, deg, t, H, h, p);
361 t =
calct(&bol, deg, Ps, H, h, *s);
366 if(!(bol || !test || j == l2)){
367 if(
xabs(t - old_T) < 0.5 *
xabs(*zero)) {
371 for(
int i = 0; i < deg; i++)
375 conv =
vrshft(10, deg, P, p, H, h, zero, s);
376 if(conv)
return conv;
380 for(
int i = 0; i < deg; i++)
384 Ps =
polyev(deg, *s, P, p);
385 t =
calct(&bol, deg, Ps, H, h, *s);
396 conv =
vrshft(10, deg, P, p, H, h, zero, s);
412 unsigned int conv = 0;
414 while(poly[0] ==
xdata.ZERO) {
424 while(poly[deg] ==
xdata.ZERO){
425 Roots[degree - deg] =
xdata.ZERO;
429 if (deg == 0)
return degree;
432 for(
int i = 0; i <= deg; i++) { P[i] = poly[i]; }
439 Roots[degree-1] = - P[1] / P[0];
447 for(
int cnt1 = 1; cnt1 <= 2; cnt1++) {
452 for(
int cnt2 = 1; cnt2 <= 9; cnt2++) {
454 PhiRand = PhiDiff * PhiRand;
458 conv =
fxshft(10 * cnt2, deg, P, p, H, h, &zero, &s);
462 Roots[degree - deg] = zero;
466 for(
int i = 0; i <= deg; i++){ P[i] = p[i]; };
487 int solve_poly(
int degree,
const double *in_real,
const double *in_imag,
double *out_real,
double *out_imag)
493 for (
int i = 0; i <= degree; ++i) {
494 poly[i].real(in_real[i]);
495 poly[i].imag(in_imag[i]);
498 nroots =
cpoly(degree, poly, roots);
500 for (
int i = 0; i < nroots; ++i) {
501 out_real[i] = roots[i].real();
502 out_imag[i] = roots[i].imag();
static xcomplex calct(bool *bol, int deg, xcomplex Ps, xcomplex *H, xcomplex *h, xcomplex s)
Definition: PolynomialSolver.h:224
ICLQt_API ImgQ sqrt(const ImgQ &image)
calls sqrt( each pixel)
static bool vrshft(const int l3, int deg, xcomplex *P, xcomplex *p, xcomplex *H, xcomplex *h, xcomplex *zero, xcomplex *s)
Definition: PolynomialSolver.h:273
undocument this line if you encounter any issues!
Definition: Any.h:37
double ZERO
Definition: PolynomialSolver.h:62
ICLQt_API core::Img< T > norm(const core::Img< T > &image)
normalize an images range to [0,255]
static void xscalbln(xcomplex *z, int e)
Definition: PolynomialSolver.h:70
int MIN_EXP
Definition: PolynomialSolver.h:62
static const struct icl::math::@18 xdata
static xreal errev(const int deg, const xcomplex *p, const xreal ms, const xreal mp)
Definition: PolynomialSolver.h:257
static bool fxshft(const int l2, int deg, xcomplex *P, xcomplex *p, xcomplex *H, xcomplex *h, xcomplex *zero, xcomplex *s)
Definition: PolynomialSolver.h:342
double xreal
Definition: PolynomialSolver.h:61
static void nexth(const bool bol, int deg, xcomplex t, xcomplex *H, xcomplex *h, xcomplex *p)
Definition: PolynomialSolver.h:237
static xreal xnorm(xcomplex z)
Definition: PolynomialSolver.h:64
ICLQt_API ImgQ abs(const ImgQ &image)
calls abs ( each pixel)
std::complex< double > xcomplex
Definition: PolynomialSolver.h:43
double INFIN
Definition: PolynomialSolver.h:62
static xreal xroot(xreal x, int n)
Definition: PolynomialSolver.h:66
static int xlogb(xcomplex z)
Definition: PolynomialSolver.h:67
static xcomplex cauchy(const int deg, xcomplex *P)
Definition: PolynomialSolver.h:78
int solve_poly(int degree, const double *in_real, const double *in_imag, double *out_real, double *out_imag)
Definition: PolynomialSolver.h:487
static void scale(const int deg, xcomplex *P)
Definition: PolynomialSolver.h:133
static xreal xabs(xcomplex z)
Definition: PolynomialSolver.h:65
int MAX_EXP
Definition: PolynomialSolver.h:62
static void noshft(const int l1, int deg, xcomplex *P, xcomplex *H)
Definition: PolynomialSolver.h:169
#define xeta(z)
Definition: PolynomialSolver.h:69
static xcomplex polyev(const int deg, const xcomplex s, const xcomplex *Q, xcomplex *q)
Definition: PolynomialSolver.h:215
int cpoly(int degree, const xcomplex poly[], xcomplex Roots[])
Definition: PolynomialSolver.h:405
#define xbits(z)
Definition: PolynomialSolver.h:68