CPython's math.hypot for two coordinates (vector_norm): the prototype's * value to the last bit, on every platform. */
| 72 | /* CPython's math.hypot for two coordinates (vector_norm): the prototype's |
| 73 | * value to the last bit, on every platform. */ |
| 74 | static double vec_norm2(double x0, double x1, double max) { |
| 75 | int max_e; |
| 76 | frexp(max, &max_e); |
| 77 | if (max_e < -1023) { |
| 78 | return DBL_MIN * vec_norm2(x0 / DBL_MIN, x1 / DBL_MIN, max / DBL_MIN); |
| 79 | } |
| 80 | double scale = ldexp(1.0, -max_e); |
| 81 | double csum = 1.0; |
| 82 | double frac1 = 0.0; |
| 83 | double frac2 = 0.0; |
| 84 | double v[2] = {x0, x1}; |
| 85 | for (int i = 0; i < 2; i++) { |
| 86 | double x = v[i] * scale; |
| 87 | dl_t pr = dl_mul(x, x); |
| 88 | dl_t sm = dl_fast_sum(csum, pr.hi); |
| 89 | csum = sm.hi; |
| 90 | frac1 += pr.lo; |
| 91 | frac2 += sm.lo; |
| 92 | } |
| 93 | double h = sqrt(csum - 1.0 + (frac1 + frac2)); |
| 94 | dl_t pr = dl_mul(-h, h); |
| 95 | dl_t sm = dl_fast_sum(csum, pr.hi); |
| 96 | csum = sm.hi; |
| 97 | frac1 += pr.lo; |
| 98 | frac2 += sm.lo; |
| 99 | double x = csum - 1.0 + (frac1 + frac2); |
| 100 | h += x / (2.0 * h); |
| 101 | return h / scale; |
| 102 | } |
| 103 | |
| 104 | static double py_hypot(double a, double b) { |
| 105 | double x0 = fabs(a); |
no test coverage detected