Documentation

Complexity.Computability.WordRAM.Signed.Encoding

Signed integers encoded in unsigned words #

An integer is stored as twice its magnitude plus a low sign bit. Zero has sign bit zero; the natural number one is not a canonical encoding. Unlike two's complement, this encoding does not depend on the word width. A signed w-bit integer, including -2^(w-1), fits in one unsigned word of w + 1 bits. The signed range is the existing GenericRAM.Signed.Fits.

Main definitions #

Main results #

References #

This representation and the bounds below are an original implementation choice, not a formalization of a cited algorithm.

Twice the magnitude, with the low bit set exactly for negative integers.

Instances For

    Interpret the low bit as a sign and the remaining bits as a magnitude.

    Instances For
      @[simp]

      The magnitude can be read by unsigned division by two.

      @[simp]

      The low bit is the sign.

      @[simp]

      Decoding an encoded integer returns that integer, including at zero.

      Different integers have different encoded words.

      Every signed w-bit integer fits in one unsigned word with one extra bit.