有谁碰到过这个怪异的问题?(50分)

  • 主题发起人 主题发起人 xchen.d
  • 开始时间 开始时间
X

xchen.d

Unregistered / Unconfirmed
GUEST, unregistred user!
var j:Integer;
y:Int64;
begin
y:=1;
for j:=1 to 24 do y:=y*j;
Edit2.Text:=IntToStr(y);

end;

y的值得到负数:-7835185981329244160

var j:Integer;
y:Int64;
begin
y:=1;
for j:=1 to 23 do y:=y*j;
Edit2.Text:=IntToStr(y);

end;

y的值得到正数:8128291617894825984
 
Some standard routines that take integer arguments truncate Int64 values to 32 bits. However, the High, Low, Succ, Pred, Inc, Dec, IntToStr, and IntToHex routines fully support Int64 arguments. Also, the Round, Trunc, StrToInt64, and StrToInt64Def functions return Int64 values. A few routines cannot take Int64 values at all.
 
很正常。。。
 
是啊,很正常...超过类型长度范围了...
 
溢出了!就是说超过系统能表示的最大整数了。
 
var
y : longword;
 
接受答案了.
 
delphi-help-输入integer 里面有详细的数据类型和长度说明 [:D]
 
longword更小,呵呵
Type Range Format
Shortint -128..127 signed 8-bit
Smallint -32768..32767 signed 16-bit
Longint -2147483648..2147483647 signed 32-bit
Int64 -2^63..2^63-1 signed 64-bit
Byte 0..255 unsigned 8-bit
Word 0..65535 unsigned 16-bit
Longword 0..4294967295 unsigned 32-bit
 
后退
顶部