TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Complex numbers in JavaScript

55 pointsby megalodonover 6 years ago

5 comments

staredover 6 years ago
Thinking for some time about refactoring Quantum Game (<a href="https:&#x2F;&#x2F;github.com&#x2F;stared&#x2F;quantum-game" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;stared&#x2F;quantum-game</a>), including its complex tensor operation part (plus some &quot;boring but important&quot; like jspm.io -&gt; webpack, actually using Vue or React vs the no-framework mess, etc). If anyone interested in collaboration, I am happy to talk!
评论 #17825850 未加载
compumikeover 6 years ago
I like how you moved to Complex16Array for reduced memory overhead and improving CPU cache performance. I&#x27;d probably take a close look at your get method&#x27;s &quot;return new Complex16(...)&quot; call and see if those object instantiations are consuming a lot of CPU time and memory churn on their own.<p>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&#x27;d want to unroll a lot of the intermediate manipulation without creating a lot of new objects in the middle! I&#x27;ve written a short complex numbers tutorial here: <a href="https:&#x2F;&#x2F;www.circuitlab.com&#x2F;textbook&#x2F;complex-numbers&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.circuitlab.com&#x2F;textbook&#x2F;complex-numbers&#x2F;</a>
评论 #17828032 未加载
chrishennover 6 years ago
Cool!<p>I once wrote a much hackier version of complex arithmetic in JavaScript [0]. It was to support a visualization of the complex derivative [1].<p>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&#x27;s `ComplexExpand` to translate from traditional notation for complex numbers [2].<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;chnn&#x2F;multivariable-derivative-viz&#x2F;blob&#x2F;master&#x2F;app&#x2F;utils&#x2F;complex-numbers.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;chnn&#x2F;multivariable-derivative-viz&#x2F;blob&#x2F;ma...</a><p>[1]: <a href="http:&#x2F;&#x2F;people.reed.edu&#x2F;~ormsbyk&#x2F;projectproject&#x2F;assets&#x2F;posts&#x2F;multivariable-derivative&#x2F;multivariable-derivative-viz&#x2F;" rel="nofollow">http:&#x2F;&#x2F;people.reed.edu&#x2F;~ormsbyk&#x2F;projectproject&#x2F;assets&#x2F;posts&#x2F;...</a><p>[2]: <a href="https:&#x2F;&#x2F;reference.wolfram.com&#x2F;language&#x2F;ref&#x2F;ComplexExpand.html" rel="nofollow">https:&#x2F;&#x2F;reference.wolfram.com&#x2F;language&#x2F;ref&#x2F;ComplexExpand.htm...</a>
javajoshover 6 years ago
Not much to say about the complex implementation itself; seems pretty good, and it&#x27;s as &#x27;bare-metal&#x27; as you can get in browser javascript. It&#x27;s not a great abstraction, and very little error checking.<p>However, I <i>really</i> like this literate programming style. You&#x27;ve got live editing, and legible output, in the form of little TeX blocks. It&#x27;s a really nice way to define, describe, and teach little libraries like this. Well done.
jwilkover 6 years ago
Why Complex<i>16</i>? What does 16 mean here?
评论 #17830590 未加载