Is the integer type `-0`

equal to `+0`

in a processing system that uses a complement of 1?

Assume the `int`

type:

Variables `negative_zero`

and

that are negative 0s, internal representations `1111<abbreviated>1111`

When there is a variable `positive_zero`

, which is a positive 0 or internal representation `0000<omitted>0000`

Is `negative_zero==positive_zero`

true or false?

`negative_zero!=positive_zero`

is true or false?

`Is negative_zero<positive_zero`

true or false?

No clear provisions were found in the scope of a glance at ISO/IEC 14882:1998.

For floating point numbers `IEEE754`

, `-0.0==+0.0`

...

2022-09-30 14:10

If you answer about standard specifications (ANSI/ISO C) instead of specific architectures, there seems to be no provision that `-0`

and `+0`

are equal.

An architecture utilizing a complement system (or a sign + absolute value) of 1 may not support `-0`

(in that case, it is treated as a trap expression), `-0`

does not occur as a normal operation result (which can only be forced to produce `-0`

.

2022-09-30 14:10

In JIS X 3014:2003 (View questions tagged with c++language specification)

Type 3.9
Section 4 Notes*37

This regulation is intended to make the memory model c++ compatible with JIS X 3010

I found the document, so I read JIS X 3010.

I found the following commentary in JIS X 3010:2003 (clanguage specification document):Here's a partial quote.

6.2.6.2 Integer type

the number where the sign bit is 1 and all the value bits are 0 (for a complement of a sign and an absolute value or two),

Alternatively, the sign bit is 1 and all value bits are 1 (for complement of 1)

A processing system definition also defines whether it is a trap expression or a normal value.

If this expression is a normal value, it is called negative 0.

If the processing system supports negative 0, the operation is:

Actual generation of negative 0s or normal 0s is not regulated.

Whether or not the negative 0 is normal when stored in an object is also undecided.

[If the processing system does not support negative 0] The result of the operation to generate negative 0 is undefined.

(No equivalent commentary was found in JIS X 3014:2003)

（ c++11 or In the first place, if the negative 0 becomes a trap expression or undefined, it should not be used.

This seems to be a pre-comparison problem.

For processing systems that use a real complement of 1 (whether c is implemented)

I think the integer match comparison is implemented as "Bit Pattern Match Comparison" as you already answered.
`-0!=+0`

is true `-0==+0`

is false.

`-0<+0`

is not enough, but the code bits are different, so I would like to expect them to be true.

("Undefined" behaviors include "how programmers expect" actions)

Well, I'm not sure how many processing systems exist or will be used to use the complement of 1.

I've never used the oil before.

Is the complement of 2 used or 1 used in the computer

2022-09-30 14:10

Reviewed the final draft C11 specification N1570.

6.5.9 Equity operators (p.96)

...

Semantics
3 The == (equal to) and != (not equal to) operators are analog to the relational operators except for their lower precedence.108) Each of the operators fields 1 if the specified relationship is true and 0 if it is false. The result has type int. For any pair of operations, of the operation.

If the specified relationship is true, it is defined as 1 and if it is false, it is defined as 0.In other words, if the * bit string is the same, it is not always true (or vice versa, if the bit string is different, it is always false).* This ** relationship** is specifically mentioned in the following sections:

7.12.14 Comparison macros (p.259)

1 The relational and equality operators support the user physical relationships between numerical values. For any ordered pair of numerical values exactly one of the relationships—less, greater, and equal—is true.

Relational and equivalent operators say they support **normal mathematical relationships** (the user mathematical relationships).(The quote above is followed by a reference to NaN.)

Based on the above, `==`

and `!=`

in C11 are equivalent in mathematical relationships.Therefore, `+0.0`

and `-0.0`

in floating-point numbers are equal (not because C11 adopts IEEE 754, but only because C11 defines floating-point numbers that can accept IEEE 754 as it is).Similarly, we assume that `+0`

and `-0`

are mathematically equal in the complement system of 1, and that `==`

is true and `!=`

is false.

C++ has not been verified.I don't have a processing system that is a complement of 1, so I don't know if that's the case.I don't have the official specification ISO/IEC 9899:2011, so I haven't been able to confirm that much.

2022-09-30 14:10

I searched the main house stackoverflow.

https://stackoverflow.com/questions/34148992/

The original question was `int negzero=-0;`

and I got stuck thinking that it was just zero (positive

That type of answer has been checked.

However, Serge Bastella's unchecked answer should be closer to what Oira is looking for this time

According to that,

ISO/IEC 9899:<Unknown>

6.2.6.2 Processing systems generate negative 0s only for the following operations:

- (snip) operator with an operand generating a negative 0

- (snip) operator where one operand is negative 0 and the result is 0

- Combined assignment operator based on the above two cases

As long as it is

```
std::cout<<(1<<negzero)<<std::endl;
std::cout<<(1>>negzero)<<std::endl;
```

Because the 式expression does not generate 0, が the negative 0 behaves the same as the positive 0 and is nothing but `1`

.

```
std::cout<<(~negzero)<(~zero)<<std::endl;
```

is defined by the processing system according to the provision that the filling bit is acceptable.

```
std::cout<<(negzero<zero)<<std::endl;
std::cout<<(negzero<=zero)<<std::endl;
std::cout<<(negzero==zero)<<std::endl;
```

Definition of processing system (because no clear wording could be found in the specification)

There is an opinion that

"Oira interprets the wording ""processing system definition"" only if it is clearly stated in the language specification, so

"
I think the latter two are "unregulated."

In JIS X 3010:2003, ISO/IEC 9899:19997.12

Integer arithmetic and string conversion functions are defined in 7.20

and so on.

`C11`

Draft `later`

is intended to be

re-written when the chapter number is determined in the adopted version.
After all, I don't think this chapter 7.12 covers integers.

LIA-1 has not yet been verified.

2022-09-30 14:10

C++20 stipulated that the signed integer type is a complement expression of 2.The C++ language no longer supports processing systems with 1 complement.

2022-09-30 14:10

Is there a 1 complement system with a C/C++ compiler?

In the old UNIVAC 1100 series, the instruction set TestEqual(=)/TestNotEqual(!==) is a simple bit comparison, so -0 and 0 are not equal to .TestZero/TestNonZero, a dedicated instruction that checks for zero instead (?), treats both -0/+0 the same way.

In summary,

`+0==-0`

: False

`+0!=-0`

: True

`+0>-0`

: True

Source (not like datasheet): Minus Zero, UNIVAC 1100 Instruction Set

2022-09-30 14:10

It's too late, but

Considering the old C, C language is originally a thin wrapper with an assembler, and considering the processing system definition as a basic concept, the result of the CPU comparison instruction (CMP in x86) is also used in one complement processing system.Therefore, if you are not sure about the specifications of the C generation (compiler specification), it may be better to look at the specifications of the CPU used.

2022-09-30 14:10

Popular Tags

python x 4436
android x 1590
java x 1475
javascript x 1385
c x 903
c++ x 831
ruby-on-rails x 681
php x 678
python3 x 651
html x 631

© 2022 OneMinuteCode. All rights reserved.