size_t compare with zero

C

CBFalconer

Richard said:
.... snip ...

I once came up with a representation like that, for this very issue. It
combines characteristics of sign-magnitude and two's complement; in
fact, one might say that it is to sign-magnitude as two's complement is
to ones'. The smallest numbers, positive and negative, run like this for
four-bit numbers:

3 0011
2 0010
1 0001
0 0000
-1 1000
-2 1001
-3 1010
-4 1011

My flabber would be deeply ghasted should a machine using this scheme
ever have been made, but it _is_ a pure binary scheme that is not
allowed by C99.
I don't think that any reasonable program that works with all allowed
C99 representations would not work with this scheme; but neither do I
think that its official absence is going to discombobulate anyone. Even
so, given that the requirement of a "pure binary" system for integers
was already in C89, I don't see why this additional requirement on
negative values was added.

I suspect the reason is that it provides no apparent advantage.
For example, sign-magnitude avoids the excessive -ve number range,
at the cost of having a negative zero. Similarly ones
complement. Both can have arithmetic implemented fairly simply.
Your method is a combination of sign-magnitude and (effectively)
twos complement, and has the disadvantages without corresponding
ease of implementation.
 

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,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top