procedure TForm1.Button2Click(Sender: TObject);
var
value1,value2:double;
p1,p2,p3,p4:PInteger;
begin
value1 := 0;
value2 := 0;
p1 := PInteger(@value1);
p2 := PInteger(Cardinal(p1)+4);
p3 := PInteger(@value2);
p4 := PInteger(Cardinal(p3)+4);
p1^ := -1337946831;
p2^ := 1115713667;
p3^ := -1337946829;
p4^ := -1031769981;
Showmessage(floattostr(value1));
Showmessage(floattostr(value2));
Showmessage(floattostr(value1+value2));
end;显示的结果是
2259428968465.65
-2259428968465.65
-0.0009765625
这样实际判断出的结果就是两数不等
但是实际上是应该相等的。
有什么好的办法能判断出两数是相等的吗?
var
value1,value2:double;
p1,p2,p3,p4:PInteger;
begin
value1 := 0;
value2 := 0;
p1 := PInteger(@value1);
p2 := PInteger(Cardinal(p1)+4);
p3 := PInteger(@value2);
p4 := PInteger(Cardinal(p3)+4);
p1^ := -1337946831;
p2^ := 1115713667;
p3^ := -1337946829;
p4^ := -1031769981;
Showmessage(floattostr(value1));
Showmessage(floattostr(value2));
Showmessage(floattostr(value1+value2));
end;显示的结果是
2259428968465.65
-2259428968465.65
-0.0009765625
这样实际判断出的结果就是两数不等
但是实际上是应该相等的。
有什么好的办法能判断出两数是相等的吗?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货