加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

德尔福柏林10.1分零缺失异常

发布时间:2020-12-15 04:17:45 所属栏目:大数据 来源:网络整理
导读:我很惊讶没有得到除零异常.我怎样才能找回来? 柏林10.1最近安装,新项目, procedure TForm1.Button1Click(Sender: TObject);var a: Double;begin a := 5/0; // No exception ShowMessage(a.ToString); // - 'INF'end; 解决方法 a := 5/0; 表达式5/0在技术语
我很惊讶没有得到除零异常.我怎样才能找回来?

柏林10.1最近安装,新项目,

procedure TForm1.Button1Click(Sender: TObject);
var
  a: Double;
begin
  a := 5/0;                     // No exception
  ShowMessage(a.ToString);      // -> 'INF'
end;

解决方法

a := 5/0;

表达式5/0在技术语言中是constant expression.

A constant expression is an expression that the compiler can evaluate without executing the program in which it occurs. Constant expressions include numerals; character strings; true constants; values of enumerated types; the special constants True,False,and nil; and expressions built exclusively from these elements with operators,typecasts,and set constructors.

因此,此表达式由编译器评估,而不是在运行时.因此,它的评估由编译时规则决定,不受运行时浮点单元异常掩码的影响.

这些规则规定正值除以零等于INF,即一个特殊的IEEE754值.如果将表达式更改为至少有一个不是常量表达式的参数,那么它将在运行时进行计算,并且将引发除零异常.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读