Is one's complement a real-world issue, or just a historical one?

后端 未结 9 816
广开言路
广开言路 2020-11-29 04:53

Another question asked about determining odd/evenness in C, and the idiomatic (x & 1) approach was correctly flagged as broken for one\'s complement-based systems, which

9条回答
  •  再見小時候
    2020-11-29 05:24

    I decided to find one. The Unisys ClearPath systems have an ANSI C compiler (yes they call it "American National Standard C" for which even the PDF documentation was last updated in 2013. The documentation is available online;

    There the signed types are all using one's complement representation, with the following properties:

    Type                 | Bits | Range
    ---------------------+------+-----------------
    signed char          |   9  |  -2⁸+1 ...  2⁸-1
    signed short         |  18  | -2¹⁷+1 ... 2¹⁷-1
    signed int           |  36  | -2³⁵+1 ... 2³⁵-1
    signed long int      |  36  | -2³⁵+1 ... 2³⁵-1
    signed long long int |  72  | -2⁷¹+1 ... 2⁷¹-1
    

    Remarkably, it also by default supports non-conforming unsigned int and unsigned long, which range from 0 ... 2³⁶ - 2, but can be changed to 0 ... 2³⁶ - 1 with a pragma.

提交回复
热议问题