E₁(z) = Γ(0, z) for complex z ≠ 0 (principal branch). Entire series * (times −ln z) for modest |z|; Legendre continued fraction for large * Re(z) > 0.
(z: Complex)
| 91 | * both are near 1 or smaller. Smith's formula then divides the scaled values, |
| 92 | * and the quotient is multiplied by `2^(ka − kb)` at the end, so it |
| 93 | * overflows only when the true quotient is outside the range of a double. |
| 94 | * |
| 95 | * A multiplication by a power of two is exact in the normal range, so when |
| 96 | * Smith's formula on the unscaled operands keeps all its values in the |
| 97 | * normal range, the result is the same, bit for bit, as the unscaled Smith |
| 98 | * formula (the one `Complex.div()` of `complex.js` uses). A part of the |
| 99 | * quotient that is exactly zero stays zero, also when the other part |
| 100 | * overflows. |
| 101 | * |
| 102 | * A dividend with an infinite part is not scaled; the result then has the |
| 103 | * infinite and NaN parts that Smith's formula gives. |
| 104 | * |
| 105 | * Known limit, shared with the unscaled `Complex.div()`: the two parts of an |
| 106 | * operand are scaled by ONE exponent (the larger one), so a part that is more |
| 107 | * than about 1000 binades smaller than its partner underflows in the scaling |
| 108 | * and its contribution to the quotient is lost. `(2^1000·i) / (2^100 + 2^-1000·i)` |
| 109 | * has the representable real part `2^-200` and answers `0` for it, as |
| 110 | * `Complex.div()` does; recovering it needs exponent-aware products. The callers handle a |
| 111 | * zero, infinite or NaN operand themselves, with their own conventions. |
| 112 | * |
| 113 | * The compiled JavaScript target uses this function too (`_SYS.cdivedge` and |
| 114 | * the complex matrix kernels in `compilation/javascript-runtime.ts`), so that |
| 115 | * the interpreter and the compiled code give the same quotient. |
| 116 | */ |
| 117 | export function scaledComplexDivide( |
| 118 | ar: number, |
| 119 | ai: number, |
| 120 | br: number, |
| 121 | bi: number |
| 122 | ): { re: number; im: number } { |
| 123 | // A divisor with one zero part divides each part of the dividend on its |
| 124 | // own: `(ar + ai·i) / br` is `ar/br + (ai/br)·i`, and |
| 125 | // `(ar + ai·i) / (bi·i)` is `ai/bi − (ar/bi)·i`. No intermediate value is |
| 126 | // formed, so a dividend whose parts differ by more than the double range |
| 127 | // keeps both of them: `(2^700 + 2^-700·i) / i` is `2^-700 − 2^700·i`. The |
| 128 | // scaling below would divide both parts by `2^700` and lose the small one |