Why can I "collapse" the range of integers by half the size without losing information?

I am trying to understand an article about lossless compression of floating point numbers and get stuck at one specific stage, in which the authors are signed with an integer from a certain range to half the size, losing the information that I think is required. I have a feeling that the authors use some standard technique, so obvious to their audience, that they do not bother to explain, but for me it is completely opaque.

The value that "adds up" is the difference between two 23-bit positive integers (predicted and actual floating-point mantissas) that lies between 1 - 2 23 and 2 23 - 1. Authors move numbers with the highest values ​​(negative and positive) "inward", so the resulting range is half the size, and each number (except 0) displays two possible values ​​from the original range. This makes me wonder how the process should be canceled in order to determine the initial value. In the authors' own words:

We calculate the signed corrector, which is the shortest modulo 2 23 and a number kthat defines the smallest interval (1-2 k 2 k ) into which this corrector falls. Then this number k, which is in the range from 0 to 22, is compressed [...]. Finally, the compressed signed equalizer bits k + 1are compressed.

Pseudo-code for this is specified as:

void comp mantissa(int expo, int a, int p) {
  // c will be within [1-2^23 ... 2^23 -1]
  int c = a - p;
  // wrap c into [1-2^22 ... 2^22 ]
  if (c <= -(1<<22)) c += 1<<23;
  else if (c > (1<<22)) c -= 1<<23;
  // find tightest [1-2^k ... 2^k ] containing c
  int k = 0;
  // loop could be replaced with faster code
  int c1 = (c < 0 ? -c : c);
  while (c1) { c1 = c1 >> 1; k++ }
  // adjust k for case that c is exactly 2k
  if (k && (c == 1<<(k-1))) k--;

  // .. further code omitted for brevity
}

Ignoring the actual compression method, the output consists of cand k. What I am not getting is: How to restore the original cfrom cand kwhen the "wrap c into" part only maps half of the potential range to the other half? I tried this on paper with 4 instead of 23 bits, and I just don't get it.

+3
1

, " 2 ^ 23", , 23- , , 2 ^ 23, "", . (. http://mathworld.wolfram.com/ModularArithmetic.html)

"wrapping" c = ap 2 ^ 23 c, , a = c + p, , 2 ^ 23 .

...

a =             00000000000000000000001
p =             10000000000000000000100
c = a-p =      -10000000000000000000011

, c <= - (1 < 22), ...

c = c+(1<<23) = 11111111111111111111101

. a c p:

a = c+p =      100000000000000000000001

23- , :

a =             00000000000000000000001

a.

+2

Source: https://habr.com/ru/post/1717333/


All Articles