去班次太大了(Go shift count too large)

编程入门 行业动态 更新时间:2024-10-18 12:26:02
班次太大了(Go shift count too large)

在Go的常量规范中 ,提到:

数字常量表示任意精度的精确值,不会溢出。

所以我试过了

const VeryVeryBigNumber = 1 << 200

它的工作原理。 但是,我可以尝试的最大移位数是511,使用512会抛出:

shift count too large: 512 。

512代表什么? 我无意使用它,我只是想知道为什么它在我的机器中限制为511(我使用ubuntu 64位并且去1.9.2)?

谢谢

In Go's constant specification, it is mentioned that:

Numeric constants represent exact values of arbitrary precision and do not overflow.

So I tried

const VeryVeryBigNumber = 1 << 200

and it works. However, the biggest shift count I could try is 511 and using 512 will throw:

shift count too large: 512.

What does 512 represents? I have no intention to use it, I just want to know why is it limited to 511 in my machine (I'm using ubuntu 64 bit and go 1.9.2)?

Thanks

最满意答案

512是任意限制。 规范唯一说的是:

实现限制:虽然数字常量在语言中具有任意精度,但编译器可以使用精度有限的内部表示来实现它们。 也就是说,每个实施必须:

表示至少256位的整数常量。

不幸的是, 围绕限制的评论并没有给出理由。

在某些时候,必须使用限制。 我建议坚持要求的256。

512 is kind of an arbitrary limit. The only thing the spec says is:

Implementation restriction: Although numeric constants have arbitrary precision in the language, a compiler may implement them using an internal representation with limited precision. That said, every implementation must:

Represent integer constants with at least 256 bits.

Unfortunately, the comments around the limits don't give a reason.

At some point, a limit has to be used. I would recommend sticking to the required 256.

更多推荐

本文发布于:2023-07-22 09:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219135.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:班次   太大了   shift   count   large

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!