x == 0 && (x & -1) != 0 for negative zero?

  • Thread starter Hallvard B Furuseth
  • Start date
D

Dik T. Winter

> Dik T. Winter wrote: ....
> | 6.2.6.2 (Representations of) Integer types, p3.
> | If the implementation supports negative zeros, they shall be
> | generated only by:
> | — the &, |, ^, ~, <<, and >> operators with arguments that
> | produce such a value;
> | — the +, -, *, /, and % operators where one argument is a
> | negative zero and the result is zero;
> | — compound assignment operators based on the above cases.
> | 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.
>
> That forbids -0 to be negative zero.

Ah, that makes implementing C on computers that use 1's complement
and are -0 preferent cumbersome! (Note that in hardware, -0
preference is the most natural with 1's complement. To get +0
preference you have to implement the addition as: ~(~a + ~b).)
 
C

CBFalconer

Dik T. Winter said:
.... snip ...


Ah, that makes implementing C on computers that use 1's complement
and are -0 preferent cumbersome! (Note that in hardware, -0
preference is the most natural with 1's complement. To get +0
preference you have to implement the addition as: ~(~a + ~b).)

No, what you need is to build everything around a subtractor,
rather than an adder. Them add becomes complement and subtract! I
realized this back in '65, about 3 months too late to incorporate
it in:

<http://cbfalconer.home.att.net/firstpc/>

which did 9's complement arithmetic excess-3 coded, 10 digit
floating point.
 
I

iRo

In data Wed, 19 Sep 2007 16:49:08 +0000 (UTC), $)CHarald van D)&k
The only forms negative zero can take are:

0xFFFF 1s' complement
0x8000 sign/magnitude.

Negative zero doesn't exist in 2's complement. And the only forms -0 can
take are:

0x0000 2's complement
0x0000 1s' complement
0x0000 sign/magnitude.

since -0 is not negative zero regardless of representation.

pheraps: unsigned i=0; --i;

so it should be "--0" and not "-0"
 
K

Keith Thompson

iRo said:
In data Wed, 19 Sep 2007 16:49:08 +0000 (UTC), $)CHarald van D)&k
<[email protected]> scrisse: [...]
Negative zero doesn't exist in 2's complement. And the only forms -0 can
take are:

0x0000 2's complement
0x0000 1s' complement
0x0000 sign/magnitude.

since -0 is not negative zero regardless of representation.

pheraps: unsigned i=0; --i;

I'm not sure what you're trying to say here. The above decrements i,
setting it to UINT_MAX.
so it should be "--0" and not "-0"

--0 is illegal, since "--" is a single token. Did you mean to apply
unary '-' twice? If so, you can write it as '- -0', or as '-(-0)'
(or, equivalently, just as 0).
 
D

Dik T. Winter

> "Dik T. Winter" wrote: ....
>
> No, what you need is to build everything around a subtractor,
> rather than an adder. Them add becomes complement and subtract!

I think CDC did that. But nonetheless, it makes implementing the standard
cumbersome of -0 preferent machines that use 1's complement.
 
R

Richard Bos

CBFalconer said:
You just generated UINT_MAX.

No, he didn't. He generated a constraint violation: the constant 0 is
not a modifiable lvalue.

Fix your .sig.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top