根据IBM Informix文档: DECIMAL(p,s)值存储在内部,第一个字节表示符号位,7位指数表示超过65格式。“超过65”格式怎么样……
该表示法特定于Informix及其DECIMAL和MONEY类型 - AFAIK,没有其他产品使用它。 Informix也在其DATETIME和INTERVAL类型中使用它,但这是大多数实现细节。
我一直都知道磁盘上的形式是'超过64',而不是'超过-65';我不确定哪个是正确的,但我认为64有一个坚实的基础。
'excess-6n'表单用于磁盘存储。它的好处是可以使用磁盘格式中的两个十进制值进行比较 memcmp() 获得正确的比较(尽管必须单独处理NULL值 - NULL值总是会导致痛苦和悲伤)。
memcmp()
该 decimal.h 来自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.还要注意'十进制'在某些方面是用词不当;数据使用'centesimal'(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
等等。