We use quite a bit of complex numbers in Javascript under the hood within CircuitLab for doing frequency-domain circuit analysis of electronic circuits like filters and amplifiers. In that mode, a circuit simulator is essentially solving a system of complex-valued equations using a sparse matrix solver that accepts complex numbers, so the complex arithmetic routines are some of the potential performance hot spots. You'd want to unroll a lot of the intermediate manipulation without creating a lot of new objects in the middle! I've written a short complex numbers tutorial here: https://www.circuitlab.com/textbook/complex-numbers/
Thank you for the link!
I once wrote a much hackier version of complex arithmetic in JavaScript [0]. It was to support a visualization of the complex derivative [1].
I found it useful to think of a complex number as a point in R^2 that operates under some different rules. I used Mathematica's `ComplexExpand` to translate from traditional notation for complex numbers [2].
[0]: https://github.com/chnn/multivariable-derivative-viz/blob/ma...
[1]: http://people.reed.edu/~ormsbyk/projectproject/assets/posts/...
[2]: https://reference.wolfram.com/language/ref/ComplexExpand.htm...
However, I really like this literate programming style. You've got live editing, and legible output, in the form of little TeX blocks. It's a really nice way to define, describe, and teach little libraries like this. Well done.