There are a few examples in the "Numeric Encoding" section of the
Wiki page titled "SQLite4: Key Encoding"¹ that I don't understand. I
think the table entries may be erroneous. By working through the
examples here, I hope to either correct my misunderstading or to get the
Wiki page corrected.

Value     Exponent E     Significand M (in hex)
=====     ==========     ======================
99.0      1              b4
99.01     1              b5 02
99.0001   1              b5 01 02

Here, in all three cases, the first centimal digit shold be 99. In the
first example, that's the only digit, so it should be encoded as

  2 * 99 = 198 = 0xC6

which is not the same as 0xB4, as shown in the current table.

Likewise, the second example should have the digits 99 and 01, which
would be multiplied as follows:

  2 * 99 + 1 = 199 = 0xC7
  2 * 01     = 2   = 0x02

Finally, the third example should have the digits 99, 00, and 01,
yielding:

  2 * 99 + 1 = 199 = 0xC7
  2 * 00 + 1 = 1   = 0x01
  2 * 01     = 2   = 0x02


Another one I can't figure out:

Value     Exponent E     Significand M (in hex)
=====     ==========     ======================
100.1     2              03 02

I expect that this should have the digits 01, 00, and 10, yielding:

  2 * 01 + 1 = 3   = 0x03
  2 * 00 + 1 = 1   = 0x01
  2 * 10     = 20  = 0x14

The table's current values 0x03 and 0x02 with exponent 2 yield 101
instead:

 (3 - 1) / 2 = 01
 2       / 1 = 01

 . 01 01 * (100 ^ 2) = .0101 * 10000 = 101


Are these examples wrong on the Wiki page, or am I misunderstanding the
encoding approach?


Footnotes: 
¹ http://www.sqlite.org/src4/doc/trunk/www/key_encoding.wiki

-- 
Steven E. Harris
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to