Undocumented Delphi 8 compiler directive FINITEFLOAT
The Delphi 8 compiler introduces the FINITEFLOAT directive.
| Type |
SWITCH |
| Syntax |
{$FINITEFLOAT ON} or {$FINITEFLOAT OFF} |
| Default |
{$FINITEFLOAT ON} |
| Scope |
Global |
Remarks
The $FINITEFLOAT directive controls the raising of exceptions and the results of floating point calculations when over/underflow occurs.
In the {$FINITEFLOAT OFF} state, floating point calculations return NaN, -INF or +INF.
In the {$FINITEFLOAT ON} state, which is the default, floating point calculations causes the compiler to emit extra code to check the results of the floating point calculations, and when the range checks fail, causes an exception to occur. These extra checks take time, so, to provide a performance boost, consider using {$FINITEFLOAT OFF}.
Quiz
In reference to the following program, consider separately, what happens in each case if
- The program is run?
- {$FINITEFLOAT OFF} is added to the top of the program and run?
- {$FINITEFLOAT ON} is added to the top of the program and run?
- x is 1.7e308, y is -5e-324, and the program is run?
- x is 1.7e308, y is -5e-324, {$FINITEFLOAT ON} and the program is run?
- x is 1.7e308, y is -5e-324, {$FINITEFLOAT OFF} and the program is run?
- x is 1.7e308, y is 1.7e308, the operation is * (multiply) not / (divide) and the program is run?
- x is 1.7e308, y is 1.7e308, {$FINITEFLOAT ON} and the operation is * (multiply) not / (divide) and the program is run?
- x is 1.7e308, y is 1.7e308, {$FINITEFLOAT OFF} and the operation is * (multiply) not / (divide) and the program is run?
{$APPTYPE CONSOLE}
uses
SysUtils;
var
x, y, z: Double;
begin
try
x := 1;
y := 0;
z := x / y;
WriteLn(z);
except
on E: Exception do
WriteLn(E.Message);
end;
end.