加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何在保持精度的同时限制Lua中的数字?

发布时间:2020-12-14 21:44:58 所属栏目:大数据 来源:网络整理
导读:原始信息: I need to multiply two 64 bit numbers,but Lua is losing precision with big numbers. (for example 99999999999999999 is shown as 100000000000000000) After multiplying I need a 64 bit solution , so I need a way to limit the solutio
原始信息:

I need to multiply two 64 bit numbers,but Lua is losing precision
with big numbers. (for example 99999999999999999 is shown as
100000000000000000) After multiplying I need a 64 bit solution,
so I need a way to limit the solution to 64 bits. (I know,if the
solution would be precise,I could just use % 0x10000000000000000,
so that would work too)

编辑:使用Lua 5.3和新的64位整数支持,此问题不再存在.整齐.

解决方法

Lua对所有数学使用双精度浮点数,包括整数运算(见 http://lua-users.org/wiki/FloatingPoint).这为您提供了大约53位的精度,(正如您所注意到的)低于您的需要.

有几种不同的方法可以在Lua中获得更好的精度.你最好的选择是找到最积极的努力并捎带它.在这种情况下,您的问题已经得到了回答;查看What is the standard (or best supported) big number (arbitrary precision) library for Lua?

如果你的Lua发行版有它的包,那么简单的答案就是lmapm.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读