A real type defines a set of numbers that can be represented with floating-point notation. The table below gives the ranges and storage formats for the fundamental real types.
Type
|
Range |
Significant digits |
Size
in bytes |
|
Real48 |
2.9 x 10^-39 .. 1.7 x 10^38 |
11~12 |
6 |
|
Single |
1.5 x 10^-35 .. 3.4 x 10^38 |
7~8 |
4 |
|
Double |
5.0 x 10^-324 .. 1.7 x 10^308 |
15~16 |
8 |
|
Extended |
3.6 x 10^-4951 .. 1.1 x 10^4932 |
19~20 |
10 |
|
Comp |
-2^63+1 .. 2^63-1 |
19~20 |
8 |
|
Currency |
-922337203685477.5808 .. 922337203685477.5807 |
19~20 |
8 |
The generic type Real, in its current implementation, is equivalent to Double.
Type
|
Range |
Significant digits |
Size
in bytes |
|
Real |
5.0 x 10^-324 .. 1.7 x 10^308 |
15~16 |
8 |
Note: The six-byte Real48 type was called Real in earlier versions
of Object Pascal. If you are recompiling code that uses the older, six-byte Real
type, you may want to change it to Real48. You can also use the {$REALCOMPATIBILITY
ON} compiler directive to turn Real back into the six-byte type.
The
following remarks apply to fundamental real types.
· Real48 is maintained for backward
compatibility. Since its storage format is not native to the Intel CPU family,
it results in slower performance than other floating-point types.
· Extended offers greater precision than
other real types but is less portable. Be careful using Extended if you
are creating data files to share across platforms.
· The Comp (computational) type is native to the Intel CPU and
represents a 64-bit integer. It is classified as a real, however, because it
does not behave like an ordinal type. (For example, you cannot increment or
decrement a Comp value.) Comp is maintained for backward
compatibility only. Use the Int64 type for better performance.
· Currency is a fixed-point data type that minimizes rounding errors in monetary calculations. It is stored as a scaled 64-bit integer with the four least-significant digits implicitly representing decimal places. When mixed with other real types in assignments and expressions, Currency values are automatically divided or multiplied by 10000.
实数类型定义了可以用浮点符号表示的数的集合。下表给出了基本实数类型的范围和存储格式:
类型
|
范围 |
精度 |
占字节数 |
|
Real48 |
2.9 x 10^-39 .. 1.7 x 10^38 |
11~12 |
6 |
|
Single |
1.5 x 10^-35 .. 3.4 x 10^38 |
7~8 |
4 |
|
Double |
5.0 x 10^-324 .. 1.7 x 10^308 |
15~16 |
8 |
|
Extended |
3.6 x 10^-4951 .. 1.1 x 10^4932 |
19~20 |
10 |
|
Comp |
-2^63+1 .. 2^63-1 |
19~20 |
8 |
|
Currency |
-922337203685477.5808 .. 922337203685477.5807 |
19~20 |
8 |
一般类型Real,在当前Object Pascal实现中等价于Double。
类型
|
范围 |
精度 |
占字节数 |
|
Real |
5.0 x 10^-324 .. 1.7 x 10^308 |
15~16 |
8 |
注意:六字节的Real48类型在Object Pascal较早的版本中叫做Real。重新编译使用了六字节Real类型的较早代码时,你也许想将其改成Real48。此时也可以用编译指示{$REALCOMPATIBILITY
ON}将Real类型转回到六字节类型。
下列注释适用于基本实数类型:
· Real48类型维持着向后兼容(向较早的版本兼容)。该类型的存储格式并非出自Intel CPU系列,因此相对其他浮点类型来说,其执行效率较慢。
· Extended比其它实数类型提供了更高的精度,但同时也占用较多的空间。当要创建跨平台共享是数据文件时,应谨慎使用该类型。
· Comp类型来自Intel CPU,表示64位的整数。将其作为实数归类,是因为该类型不具备序数类型的一些特征(如,不能对Comp值进行递增或递减)。Comp类型仅用于向后兼容,因此在新的代码中应当使用Int64类型以获得更好的性能。
· Curreny是定点数据类型,该类型在货币计算时使舍入误差最小。Currency类型以含格式的64位整数存储,其中隐含地包括了表示小数部分的4位最少有效数字。在赋值语句和表达式中将该类型与其他实数类型混合时,Currency类型的值会自动被除以或乘以10000。(大多数货币数字都只含有2位小数,Currency类型总是保留4位小数,这就足以使货币计算的误差降到最小。)
编者注
对于向较早版本的兼容,从时间前后的角度来说,应叫做“向前兼容”,而从新旧前后的角度来说,应叫做“向后兼容”。本参考结合原文以及一般习惯,采用后者。因此,凡在本参考中出现“向后兼容”,均指向较早(或旧、老)的版本兼容。