MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / ellipticEComplex

Function ellipticEComplex

src/compute-engine/numerics/numeric-complex.ts:267–287  ·  view source on GitHub ↗
(m: Complex)

Source from the content-addressed store, hash-verified

265 const d = z.re * z.re + z.im * z.im;
266 const nr = a.re * z.re + a.im * z.im;
267 const ni = a.im * z.re - a.re * z.im;
268 if (textbookQuotientIsAccurate(a.re, a.im, z.re, z.im, d, nr, ni))
269 return a.div(z);
270 const q = scaledComplexDivide(a.re, a.im, z.re, z.im);
271 return new Complex(q.re, q.im);
272}
273
274/**
275 * `1 / z` for a `complex.js` value, a drop-in replacement for
276 * `z.inverse()`, computed with `complexQuotient()`. It does not overflow or
277 * underflow when the result is in the range of a double. (The unpatched
278 * `z.inverse()` of `complex.js` computes `conj(z) / |z|²`, whose `|z|²`
279 * overflows for `z = 1e308 + 1e308·i` and underflows for
280 * `z = 1e-200 + 1e-200·i`. `installComplexScaling()` in
281 * `numerics/complex-scaling.ts` corrects `z.inverse()` for these values
282 * too.) A zero, infinite or NaN value is left to `z.inverse()`, so its
283 * result does not change.
284 */
285export function complexInverse(z: Complex): Complex {
286 if (z.isZero() || !Number.isFinite(z.re) || !Number.isFinite(z.im))
287 return z.inverse();
288 const q = complexQuotient(1, 0, z.re, z.im);
289 return new Complex(q.re, q.im);
290}

Callers 1

Calls 9

equalsMethod · 0.65
sqrtMethod · 0.65
subMethod · 0.65
mulMethod · 0.65
addMethod · 0.65
absMethod · 0.65
negMethod · 0.65
divMethod · 0.65
isNaNMethod · 0.45

Tested by

no test coverage detected