Originale-mail to me for new edition

 

Numerals

 

Integer and real constants can be represented in decimal notation as sequences of digits without commas or spaces, and prefixed with the + or - operator to indicate sign. Values default to positive (so that, for example, 67258 is equivalent to +67258) and must be within the range of the largest predefined real or integer type.

Numerals with decimal points or exponents denote reals, while other numerals denote integers. When the character E or e occurs within a real, it means times ten to the power of. For example, 7E-2 means 7 * 10^-2, and 12.25e+6 and 12.25e6 both mean 12.25 * 10^6.

The dollar-sign prefix indicates a hexadecimal numeral, for example, $8F. Hexadecimal numbers without a preceding '-' unary operator are taken to be positive values. During an assignment, if a hexadecimal value lies outside the range of the receiving type an error is raised, except in the case of the Integer (32-bit Integer) where a warning is raised. In this case, values exceeding the positive range for Integer are taken to be negative numbers in a manner consistent with 2's complement integer representation.

For more information about real and integer types, see Data types, variables, and constants. For information about the data types of numerals, see True constants.

 

Topic groups

 

See also

Character strings

Directives

Fundamental syntactic elements: Overview

Identifiers

Labels

Reserved words

Special symbols

 

 

译文

 

数字

 

整数和实数常量可以十进制的阿拉伯数字序列来表示,序列中不能含有逗号、空格等分节符(例如:数字 123,444,567.000 中使用了逗号因而在Object Pascal中不合法)。数字常量前缀正号(+)或负号(-),用于表示数字的符号。缺省情况下数值是正的(因此,例如,67258 等价于 +67258),而且其数值必需在预先定义的最大实数或整数类型范围中。

含有小数点或指数的数字表示的是小数,其他数字表示的是整数。当字符 E e 出现在实数中时,意味着是乘以10的幂。例如,7E-2表示的是 7 * 10^-27乘以10 -2次幂),12.25e+6 12.25e6都表示 12.25 * 10^6

美圆符号前缀表示16进制数字,如 $8F 。没有前缀一元运算符“-”(负号)的16进制数字也可以表示负值。赋值时,如果16进制数值在被赋值类型范围之外,那么将引发异常。而如果是向32位的Integer类型赋值,数值超出范围时只提出警告而不引发异常。这种情况下,超出Integer类型正数范围的数值将作为负数被接受(一致习惯用2进制补码表示)。

有关实数和整数类型的更多信息,见数据类型、变量和常量;有关数字数据类型的更多信息,见真实常量

 

主题组

 

相关主题

字符串

指示字

基本语法元素:概述

标识符

标号

保留字

特殊符号

 

 

编者注

严格地说,向Integer类型赋正数值时如果超出范围,此时对于其内存数据并没有做任何操作,只是因为对数字解释的方式不同而表现出相异的数值。请看下面的范例:

 

var

  { Integer类型的范围是 -2147483648..2147483647

    正数最大值用16进制表示是 $7FFFFFFF }

  A, B: Integer;

  { Cardinal类型的范围是 0..4294967295 }

  C, D: Cardinal;

begin

  { 16进制数已经超过Integer类型正数最大值 }

  C := $EFAB1234;

  A := C;

  B := - (not C + 1);

  D := - (not C + 1);

  if A = B then

    ShowMessage('A = B, ' + IntToStr(A));

  if A <> C then

    ShowMessage('A (' + IntToStr(A) + ') <> C (' + IntToStr(C) + ')');

  if C = D then

    ShowMessage('C = D, ' + IntToStr(C));

end;

 

在本例中,三个if语句中的条件判定都将为真,即此时 A = BC = DA <> C。在Object Pascal中,Integer类型和Cardinal类型都占用4字节(32位),前者是含符号的整数类型,后者是无符号的整数类型。因此,尽管在变量AC的存储空间中的数据相同,但表示的值却不同。由于本例中对变量C的赋值超出了Integer类型的正数范围,所以Object PascalA解释成为一个负的整数(2进制序列的最高位表示符号,此位为1时表示负号,此位为0时表示正号)。

本例中还可以看出,无论是含符号整数类型还是无符号整数类型,对其进行 not 逻辑运算,然后加1,最后再将其符号改变,得到的整数数值与最初的数值是相等的。