gpt4 book ai didi

prolog - 负整数的表示

转载 作者:行者123 更新时间:2023-12-02 04:46:15 25 4
gpt4 key购买 nike

ISO-Prolog 有什么处方/建议吗 关于负整数的表示及其运算? 2的补码,也许吧?

作为程序员/用户询问:在对负整数执行位级操作时,我可以安全地做出任何假设吗?

最佳答案

ISO/IEC 13211-1 对整数有一些要求,但没有要求具体的表示形式。如果整数表示有界,则满足以下条件之一

7.1.2 Integer

...

minint = -(*minint)
minint = -(maxint+1)

此外,9.4 Bitwise functors 中列出的可评估仿函数,即(>>)/2 , (<<)/2 , (/\)/2 , (\/)/2 , (\)/1 ,和xor/2是为负值定义的实现。例如,

8.4.1 (>>)/2 – bitwise right shift

9.4.1.1 Description

...
The value shall be implementation defined depending on
whether the shift is logical (fill with zeros) or arithmetic
(fill with a copy of the sign bit).

The value shall be implementation defined if VS is negative,
or VS is larger than the bit size of an integer.

请注意,定义的实现意味着符合要求的处理器必须在随附的文档中记录这一点。所以在使用合格的处理器之前,你必须阅读手册。

事实上,当前的 Prolog 处理器(据我所知)不提供算术右移并且不使用 2's complement .

关于prolog - 负整数的表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30210801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com