/** * @brief Compute Aberth correction for the j-th root, * but only with other roots of the <code>jc</code>-th * cluster. */ void mps_faberth_s (mps_context * s, mps_approximation * ab_root, mps_cluster * cluster, cplx_t abcorr) { cplx_t z; mps_root * root; cplx_set (abcorr, cplx_zero); for (root = cluster->first; root != NULL; root = root->next) { mps_approximation * appr = s->root[root->k]; if (appr == ab_root) continue; cplx_sub (z, ab_root->fvalue, appr->fvalue); cplx_inv_eq (z); cplx_add_eq (abcorr, z); } }
/** * @brief Compute Aberth correction for j-th root, without * selective correction. */ void mps_faberth (mps_context * s, mps_approximation * root, cplx_t abcorr) { cplx_t z; int i; cplx_set (abcorr, cplx_zero); for (i = 0; i < s->n; i++) { if (s->root[i] == root) continue; cplx_sub (z, root->fvalue, s->root[i]->fvalue); cplx_inv_eq (z); cplx_add_eq (abcorr, z); } }
void cplx_pow_eq_si (cplx_t x, register signed long int i) /* x = x ^ i , i integer */ { cplx_t t; cplx_Move (t, x); cplx_Move (x, cplx_one); if (i < 0) { cplx_inv_eq (t); i = -i; } while (i) { if (i & 1) cplx_mul_eq (x, t); cplx_sqr_eq (t); i >>= 1; /* divide i by 2 */ } }
void mps_faberth_wl (mps_context * s, int j, cplx_t abcorr, pthread_mutex_t * aberth_mutexes) { int i; cplx_t z, froot; pthread_mutex_lock (&aberth_mutexes[j]); cplx_set (froot, s->root[j]->fvalue); pthread_mutex_unlock (&aberth_mutexes[j]); cplx_set (abcorr, cplx_zero); for (i = 0; i < s->n; i++) { if (i == j) continue; pthread_mutex_lock (&aberth_mutexes[i]); cplx_sub (z, froot, s->root[i]->fvalue); pthread_mutex_unlock (&aberth_mutexes[i]); cplx_inv_eq (z); cplx_add_eq (abcorr, z); } }