* Precompute GCD and bounds transformations */
| 254 | * Precompute GCD and bounds transformations |
| 255 | */ |
| 256 | static int |
| 257 | diophantine_precompute(unsigned int n, |
| 258 | diophantine_term_t *E, |
| 259 | diophantine_term_t *Ep, |
| 260 | npy_int64 *Gamma, npy_int64 *Epsilon) |
| 261 | { |
| 262 | npy_int64 a_gcd, gamma, epsilon, c1, c2; |
| 263 | unsigned int j; |
| 264 | char overflow = 0; |
| 265 | |
| 266 | assert(n >= 2); |
| 267 | |
| 268 | euclid(E[0].a, E[1].a, &a_gcd, &gamma, &epsilon); |
| 269 | Ep[0].a = a_gcd; |
| 270 | Gamma[0] = gamma; |
| 271 | Epsilon[0] = epsilon; |
| 272 | |
| 273 | if (n > 2) { |
| 274 | c1 = E[0].a / a_gcd; |
| 275 | c2 = E[1].a / a_gcd; |
| 276 | |
| 277 | /* Ep[0].ub = E[0].ub * c1 + E[1].ub * c2; */ |
| 278 | Ep[0].ub = safe_add(safe_mul(E[0].ub, c1, &overflow), |
| 279 | safe_mul(E[1].ub, c2, &overflow), &overflow); |
| 280 | if (overflow) { |
| 281 | return 1; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | for (j = 2; j < n; ++j) { |
| 286 | euclid(Ep[j-2].a, E[j].a, &a_gcd, &gamma, &epsilon); |
| 287 | Ep[j-1].a = a_gcd; |
| 288 | Gamma[j-1] = gamma; |
| 289 | Epsilon[j-1] = epsilon; |
| 290 | |
| 291 | if (j < n - 1) { |
| 292 | c1 = Ep[j-2].a / a_gcd; |
| 293 | c2 = E[j].a / a_gcd; |
| 294 | |
| 295 | /* Ep[j-1].ub = c1 * Ep[j-2].ub + c2 * E[j].ub; */ |
| 296 | Ep[j-1].ub = safe_add(safe_mul(c1, Ep[j-2].ub, &overflow), |
| 297 | safe_mul(c2, E[j].ub, &overflow), &overflow); |
| 298 | |
| 299 | if (overflow) { |
| 300 | return 1; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | |
| 309 | /** |
no test coverage detected