| 840 | return y < 0 || (y === 0 && x < 0) |
| 841 | ? new Complex(phi, -l) |
| 842 | : new Complex(-phi, l); |
| 843 | } |
| 844 | // 1 − w = (z − 1)/z and 1 + w = (z + 1)/z, with w = 1/z. |
| 845 | let p: { re: number; im: number }; |
| 846 | let q: { re: number; im: number }; |
| 847 | if (y === 0) { |
| 848 | // A real w: the imaginary part is the zero of `complexAcos()`. |
| 849 | const wi = x > 0 ? -0 : 0; |
| 850 | p = { re: (x - 1) / x, im: -wi }; |
| 851 | q = { re: (x + 1) / x, im: wi }; |
| 852 | } else if (h > 2) { |
| 853 | // |w| < 1/2: 1 ± w has no cancellation, while z ± 1 would lose the 1. |
| 854 | const w = complexQuotient(1, 0, x, y); |
| 855 | p = { re: 1 - w.re, im: -w.im }; |
| 856 | q = { re: 1 + w.re, im: w.im }; |
| 857 | } else { |
| 858 | p = complexQuotient(x - 1, y, x, y); |
| 859 | q = complexQuotient(x + 1, y, x, y); |
| 860 | } |
| 861 | const [ar, ai] = sqrtParts(p.re, p.im); // √(1 − w) |
| 862 | const [br, bi] = sqrtParts(q.re, q.im); // √(1 + w) |
| 863 | return new Complex(2 * Math.atan2(ar, br), Math.asinh(br * ai - bi * ar)); |