Erlang长64号BUG

发布于 2024-09-15 03:07:54 字数 317 浏览 3 评论 0原文

如果操作数之一不够大,Erlang 就会截断大长操作的值。 尽管如果两个操作数都足够大,则不会截断。

199> 3656626623097354252900000 * 11111111111111111111111111. 
40629184701081713921111110704819264100293971900000
200> 3656626623097354252900000 * 64.                     
234024103878230672185600000

有什么线索吗?或者说这确实是一个BUG?

Erlang is truncating the value of big long operations if one of the operands are not big enough.
Although it is not truncating if both operands are big enough.

199> 3656626623097354252900000 * 11111111111111111111111111. 
40629184701081713921111110704819264100293971900000
200> 3656626623097354252900000 * 64.                     
234024103878230672185600000

Any clue why? Or it is really a BUG?

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

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

发布评论

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

评论(2

冧九 2024-09-22 03:07:54

刚刚使用 GHCI(格拉斯哥哈斯克尔解释器)尝试了这两个操作,它返回了完全相同的结果。

不确定您是否意识到这一点,但 Erlang 支持 bignums

在计算机科学中,
任意精度算术是
计算的技术
对数字为
精度仅受以下限制
主机系统的可用内存。
这与更快的形成对比
固定精度算术发现于
大多数 ALU 硬件,通常
提供小数点后 6 到 16 之间的报价
数字。它也被称为bignum
算术,有时甚至
“无限精度算术”(其中
是一个用词不当,因为
数字既有限又有界
练习)。

Just tried both operations using GHCI (The Glasgow Haskell Interpreter) and it gave back exactly the same result.

Not sure if you are aware of this, but Erlang supports bignums:

In computer science,
arbitrary-precision arithmetic is a
technique whereby calculations are
performed on numbers whose digits of
precision are limited only by the
available memory of the host system.
This contrasts with the faster
fixed-precision arithmetic found in
most ALU hardware, which typically
offers between 6 and 16 decimal
digits. It is also called bignum
arithmetic, and sometimes even
"infinite-precision arithmetic" (which
is a misnomer, since the number of
digits is both finite and bounded in
practice).

自演自醉 2024-09-22 03:07:54

这不是一个错误。 Erlang 具有任意精度的整数。 (实际上,这当然受到机器上可用内存的限制......)

这些整数是使用称为“fixnum”和“bignum”的东西来实现的。 Fixnum 是适合 32 位架构上的 28 位或 64 位架构上的 60 位的(有符号)整数。附加位用于类型标记(请记住,Erlang 是动态强类型的,因此需要对其值进行类型标记)。然后,Erlang 虚拟机切换到大于该大小的 bignum。这些措施的实施效率要低得多。

除了保持在固定数范围内之外,添加 HiPE 编译,程序的算术部分应该具有“接近 C 的速度”。

This is not a bug. Erlang has arbitrary precision integers. (In practice this is limited by the available memory on the machine of course...)

These integers are implemented using something called "fixnum" and "bignum". Fixnums are (signed) integers fitting 28 bits on 32 bit architecture or 60 bits on a 64 bit architecture. The additional bits are used for type tagging (remember that Erlang is dynamically strongly typed and thus needs type tags on its values). The Erlang virtual machine then switches to bignum above that size. These are far less efficiently implemented.

Add HiPE compilation on top of staying within the fixnum range and you should have "close to C speed" for the arithmetic parts of the program.

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