Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi Berlin 10.1 Division by zero exception missing

I am surprised not the get division by zero exception. How do I get it back?

Berlin 10.1 very recent install, new project,

procedure TForm1.Button1Click(Sender: TObject);
var
  a: Double;
begin
  a := 5/0;                     // No exception
  ShowMessage(a.ToString);      // -> 'INF'
end;
like image 663
Doege Avatar asked Dec 02 '17 19:12

Doege


1 Answers

a := 5/0;

The expression 5/0 is, in technical language terms, a 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.

As such this expression is evaluated by the compiler, and not at runtime. So its evaluation is determined by compile time rules and cannot be influenced by runtime floating point unit exception masks.

And those rules state that positive value divided by zero is equal to +INF, a special IEEE754 value. If you change the expression to have at least one argument that is not a constant expression then it will be evaluated at runtime, and a divide by zero exception will be raised.

like image 57
David Heffernan Avatar answered Sep 24 '22 00:09

David Heffernan