【问题标题】:What is the excess-65 exponent format?什么是超过 65 的指数格式?
【发布时间】:2019-07-08 14:22:55
【问题描述】:

根据 IBM Informix 文档:

DECIMAL(p, s) 值在内部存储,第一个字节表示符号位和超过 65 格式的 7 位指数。

“excess-65”格式如何工作?

参考文献

  1. DECIMAL(p,s) Data Types
  2. DECIMAL Storage

【问题讨论】:

标签: binary decimal storage informix exponent


【解决方案1】:

该符号特定于 Informix 及其 DECIMAL 和 MONEY 类型 — AFAIK,没有其他产品使用它。 Informix 还在其 DATETIME 和 INTERVAL 类型中使用它,但大部分情况下这是一个实现细节。

我一直都知道磁盘上的形式是“excess-64”而不是“excess-65”;我不确定哪个是正确的,但我认为 64 有坚实的基础。

“excess-6n”形式用于磁盘存储。它的好处是可以使用memcmp() 比较磁盘格式中的两个十进制值以获得正确的比较(尽管必须单独处理 NULL 值 - NULL 值总是会导致痛苦和悲伤)。

来自 ESQL/C(和 C-ISAM)的 decimal.h 标头包含以下信息:

/*
 * Packed Format  (format in records in files)
 *
 *    First byte =
 *        top 1 bit = sign 0=neg, 1=pos
 *        low 7 bits = Exponent in excess 64 format
 *    Rest of bytes = base 100 digits in 100 complement format
 *    Notes --  This format sorts numerically with just a
 *              simple byte by byte unsigned comparison.
 *              Zero is represented as 80,00,00,... (hex).
 *              Negative numbers have the exponent complemented
 *              and the base 100 digits in 100's complement
 */

注意这里提到的是 64 而不是 65。还要注意“十进制”在某些方面是用词不当;数据使用“百分位”(base-100)表示法表示。

这里有一些示例值、十进制表示,然后是磁盘格式的字节。请注意,在某种程度上,字节数是任意的。如果使用 DECIMAL(16,4) 之类的东西,将有 1 个字节的符号和指数以及 8 个字节的数据(并且指数的范围将受到限制)。如果您使用 DECIMAL(16)(浮点数),则指数范围的限制要小得多。

Decimal value          Byte representation (hex)
 0                     80 00 00 00 00
 1                     C1 01
-1                     3E 63
 9.9                   C1 09 5A 00
-9.9                   3E 5A 0A 00
 99.99                 C1 63 63 00 00 00
-99.99                 3E 00 01 00 00 00
 999.999               C2 09 63 63 5A
-999.999               3D 5A 00 00 0A
 0.1                   C0 0A 00 00
-0.1                   3F 5A 00 00
 0.00012345            BF 01 17 2D 00
-0.00012345            40 62 4C 37 00
 1.2345678901234e-09   BC 0C 22 38 4E 5A 0C 22
-1.2345678901234e-09   43 57 41 2B 15 09 57 42
 1.2345678901234e+09   C5 0C 22 38 4E 5A 0C 22
-1.2345678901234e+09   3A 57 41 2B 15 09 57 42

等等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-17
    • 2014-03-17
    • 2010-11-25
    • 2011-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多