是否有任何实现支持负零或将其保留为陷阱表示的实现? [英] Are there any implementations that support a negative zero, or reserve it as a trap representation?

查看:87
本文介绍了是否有任何实现支持负零或将其保留为陷阱表示的实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在当今的大多数实现中,带符号的整数值的符号位模式为1,而值为0的位模式都倾向于表示该带符号的整数类型的最低值。

On most implementations of this day and age, a signed integer value that has a bit pattern of 1 for the sign bit and all 0 for the value bits tends to represent the lowest possible value for that signed integer type.

但是,如 6.2.6.2 p2 指出,这不是必需条件:

However, as 6.2.6.2p2 states, that's not a requirement:


其中哪些适用于实现定义,带符号的值是否也是如此位1和所有值位为零(对于前两个),或带符号位和所有值位为1(对1的补码),是陷阱表示形式或正常值。

Which of these applies is implementation-defined, as is whether the value with sign bit 1 and all value bits zero (for the first two), or with sign bit and all value bits 1 (for ones' complement), is a trap representation or a normal value.

我的第一个问题很简单:是否有任何使用此位模式表示负零或陷阱表示的实现?如果对这个问题的回答为否,那么对我的后续问题的回答也必须为否。

My first question is simple: Are there any implementations that use this bit pattern for a negative zero or a trap representation? If the answer to this question is 'no', then the answer to my follow-up questions must also be 'no'.

接着是该问题, 6.2.6.2p3 指出,当为对象分配负零时,它可能会(也可能不会)被转换为正零:

Following on from that question, 6.2.6.2p3 states that when a negative zero is assigned to an object, it might (or might not) be converted to a regular zero:


目前尚不清楚这些情况是产生负零还是正常零,以及存储在对象中时负零是否变为正常零。

It is unspecified whether these cases actually generate a negative zero or a normal zero, and whether a negative zero becomes a normal zero when stored in an object.

我的后续问题:


  1. 有没有使用陷阱表示而不是该位模式为负零的实现?

  2. 是否有使用负零存储为不同值的实现?

  3. 是否有任何使用负零存储为常规零的实现?






编辑以澄清问题:我询问在使用带符号补码,二进制补码或符号和大小表示的带符号整数的系统中理论上是可行的。在本问题前面的部分中,我可以找到(并且已经找到)该信息。我问的是实际完成的事情


edit for clarification: I am NOT asking for what is theoretically possible in a system that uses ones complement, twos complement or sign and magnitude representations for signed integers. I can find (and have found) that information in the sections I've cited from earlier in this question. I'm asking about what has actually been done.

推荐答案

在评论中, Iskar Jarak 引起了我的注意,OS2200的最新版本于2015年2月发布C的实现称为 UCS C ,其中手册文档

As brought to my attention by Iskar Jarak within the comments, the OS2200, which was most recently released in February of 2015, has an implementation of C known as UCS C, of which the manual documents


  • 符合标准的C实现方式, ...不使用CONFORMANCE / TWOSARITH,在所有使用小于(<)或等于(=)的36位无符号整数比较中,负零等于零。在使用大于(>),(2 36 )-1大于零。

  • 一个符合标准的C实现,其中 CONFORMANCE / TWOSARITH导致负零,( 2 36 )-1,被认为是一个大的无符号整数。因为这违反了几个C标准子句( 6.2.6.2p2 指出符号位的值为-(2 M )(二进制补码) 符号位的值为-(2 M -1)(一个补码) 6.3.1.1p3 指出整数促销保留包含符号的值 ,与转换为在UCS / OS2200文档中指定的一个大的无符号整数),那么只有当负零位模式被视为陷阱表示,从而调用未定义的行为,并且

  • a conforming C implementation where-by "... CONFORMANCE/TWOSARITH is not used, negative zero is equivalent to zero in all 36-bit unsigned integer comparisons using less than (<), or equal (=). In unsigned comparisons using greater than (>), (236)-1 is greater than zero."
  • a questionably-conforming C implementation where-by "CONFORMANCE/TWOSARITH causes negative zero, (236)-1, to be considered a large unsigned integer by the generated code." As this violates several C standard clauses (6.2.6.2p2 stating "the sign bit has the value -(2M) (two's complement)" and "the sign bit has the value -(2M-1) (ones' complement)", 6.3.1.1p3 stating "The integer promotions preserve value including sign", in contradiction to the conversion to a large unsigned integer specified within the UCS/OS2200 doc) it follows that this could only conform if the negative zero bit pattern is treated as a trap representation, where-by undefined behaviour is invoked and so the constraints of the standard no longer apply.

总之,...


是否有任何使用此位模式的负零或陷阱表示的实现

是。所提供的示例可以将此位模式用于负零陷阱表示,具体取决于编译器的一致性选项。

Yes. The example provided can use this bit pattern for a negative zero or a trap representation, depending upon compiler conformance options.

对于后续问题1和2,可以得出OS2200上的UCS C都是这两个示例。

For the follow-up questions 1&2, it follows that UCS C on OS2200 is an example of both of these.

问题3 ,待改天再回答...我的时间到这里结束了:)

As for question 3, to be answered another day... My time has come to end here :)

这篇关于是否有任何实现支持负零或将其保留为陷阱表示的实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆