JavaScript 中处理大数 (BigNum) 的标准解决方案是什么?

发布于 2024-09-06 08:50:37 字数 529 浏览 12 评论 0原文

JavaScript 或浏览器中是否内置了 bignum?

另一种方法是加载外部库,

<script type="text/javascript" src="the_bignum_library.js"></script>

但这似乎很慢并且可能会触发安全警告。

我考虑过基于 http://github.com/silentmatt/javascript-biginteger 或 http://www.mainebrook.com/john/fun/euler.html 。或者,是否有调用 Java bignum 库(例如 apfloat)的解决方案?

Is there a bignum built into JavaScript or browsers?

The alternate is loading an external library like

<script type="text/javascript" src="the_bignum_library.js"></script>

but that seems slow and may trigger a security warning.

I've considered basing my own off of http://github.com/silentmatt/javascript-biginteger or http://www.mainebrook.com/john/fun/euler.html. Alternately, is the solution to call into a Java bignum library such as apfloat?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2024-09-13 08:50:37

更新(2019-08-19):BigInt< /a> 现在是 Firefox 和 Chrome 的一部分;你不再需要图书馆:

const bigInt1 = 1111111111111111111111111111111n;
const bigInt2 = BigInt("1111111111111111111111111111111")
console.log((bigInt1 + bigInt2)+"")

原始答案:

如果您需要任意精度的十进制数字,请使用 Javascript-bignum,因为它是正确的而且速度快。

Update(2019-08-19): BigInt is now part of Firefox and Chrome; you no longer need a library:

const bigInt1 = 1111111111111111111111111111111n;
const bigInt2 = BigInt("1111111111111111111111111111111")
console.log((bigInt1 + bigInt2)+"")

Original answer:

If you need arbitrary-precision decimal numbers, use Javascript-bignum, as it is correct and fast.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文