Kro*_*ica 4 delphi floating-point variant
我惊讶地发现,浮点值可以用Delphi中的Variant来划分.可以做什么的简单示例:
var
v: Variant;
begin
v := 2.3;
Tag := 5.1 div v; // 2
Tag := 5.1 mod v; // 1
Tag := 5.1 div 2; // [dcc32 Error] E2015 Operator not applicable to this operand type
Tag := 5.1 mod 2; // [dcc32 Error] E2015 Operator not applicable to this operand type
end;
Run Code Online (Sandbox Code Playgroud)
在进行div/ mod操作之前,看起来Delphi会对左部分和右部分进行舍入.
我希望上面的代码在编译时在所有4行中产生错误,因为我的理解是div/mod不适用于浮点值,无论如何.显然情况并非如此.
为什么我可以在Delphi中将Single by Variant分开,它需要什么?
| 归档时间: |
|
| 查看次数: |
264 次 |
| 最近记录: |