TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Is there a JavaScript library for arbitrary precision complex mathematics?

5 点作者 valera_rozuvan将近 9 年前
I am looking for a JavaScript library to work with very small (very large) complex numbers. I need things like pow(), sqrt(), etc. Best I could find is Math.js [1], but it doesn&#x27;t have arbitrary precision functions for complex numbers. To illustrate my point, please see this JSFiddle [2].<p>If there is no such library - what is the best alternative?<p>a.) create such a library from scratch<p>b.) convert some Java, Python, or C&#x2F;C++ library to JavaScript using pyjs or Emscripten<p>[1] http:&#x2F;&#x2F;mathjs.org&#x2F;<p>[2] https:&#x2F;&#x2F;jsfiddle.net&#x2F;95mxb0dL&#x2F;12&#x2F;

4 条评论

niftich将近 9 年前
Though I&#x27;m sure you&#x27;d rather avoid it, you can inspect other bignum implementations and perform a port. Coming from a Java library, for example, the port would be relatively straightforward, as syntax and semantics will largely match.<p>The most unpleasant thing is that JS doesn&#x27;t have native ints, so you&#x27;ll have to either use some other type as backing storage, and&#x2F;or clever type coercion trickery, like what you see in asm.js.<p>[1] apfloat: <a href="http:&#x2F;&#x2F;grepcode.com&#x2F;snapshot&#x2F;repo1.maven.org&#x2F;maven2&#x2F;org.apfloat&#x2F;apfloat&#x2F;1.8.2&#x2F;" rel="nofollow">http:&#x2F;&#x2F;grepcode.com&#x2F;snapshot&#x2F;repo1.maven.org&#x2F;maven2&#x2F;org.apfl...</a><p>[2] JDK&#x27;s BigDecimal: <a href="http:&#x2F;&#x2F;grepcode.com&#x2F;file&#x2F;repository.grepcode.com&#x2F;java&#x2F;root&#x2F;jdk&#x2F;openjdk&#x2F;8u40-b25&#x2F;java&#x2F;math&#x2F;BigDecimal.java#BigDecimal" rel="nofollow">http:&#x2F;&#x2F;grepcode.com&#x2F;file&#x2F;repository.grepcode.com&#x2F;java&#x2F;root&#x2F;j...</a>
评论 #12169221 未加载
niftich将近 9 年前
There are not many JS libraries in this space that have sane handling for complex numbers and arbitrary precision.<p>I&#x27;m not entirely sure, but perhaps NumericJS [1] would have what you&#x27;re looking for?<p>[1] <a href="http:&#x2F;&#x2F;www.numericjs.com&#x2F;documentation.html" rel="nofollow">http:&#x2F;&#x2F;www.numericjs.com&#x2F;documentation.html</a>
评论 #12168964 未加载
antoineMoPa将近 9 年前
We should write a library for that with webgl + GLSL backend for faster computation (It would be quite a hack: textures would be used to store data and communicate with JS, but everything would be much faster). We could also use WebCL but this thing does not seem to work with many browsers.
评论 #12175565 未加载
S4M将近 9 年前
I had a look at your jsfiddle, and it looks to me that it&#x27;s a bug in mathjs. I have the impression that mathjs doesn&#x27;t parse well complex numbers (I can be wrong there), so why not spend 1 hour to try to fix that bug before considering alternatives?
评论 #12175534 未加载