JavaScript 64 位数字精度 [英] JavaScript 64 bit numeric precision
本文介绍了JavaScript 64 位数字精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 JavaScript 中表示一个高于 53 位精度的数字?换句话说,有没有办法表示 64 位精度数?
Is there a way to represent a number with higher than 53-bit precision in JavaScript? In other words, is there a way to represent 64-bit precision number?
我正在尝试实现一些逻辑,其中 64 位数字的每一位都代表某些内容.当我尝试将位设置为高于 2^53 时,我会丢失较低的有效位.
I am trying to implement some logic in which each bit of a 64-bit number represents something. I lose the lower significant bits when I try to set bits higher than 2^53.
Math.pow(2,53) + Math.pow(2,0) == Math.pow(2,53)
有没有办法实现自定义库或其他东西来实现这一点?
Is there a way to implement a custom library or something to achieve this?
推荐答案
Google 的 Closure 库有 goog.math.Long 用于此目的.
Google's Closure library has goog.math.Long for this purpose.
这篇关于JavaScript 64 位数字精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文