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

  1. The program is run?
  2. {$FINITEFLOAT OFF} is added to the top of the program and run?
  3. {$FINITEFLOAT ON} is added to the top of the program and run?
  4. x is 1.7e308, y is -5e-324, and the program is run?
  5. x is 1.7e308, y is -5e-324, {$FINITEFLOAT ON} and the program is run?
  6. x is 1.7e308, y is -5e-324, {$FINITEFLOAT OFF} and the program is run?
  7. x is 1.7e308, y is 1.7e308, the operation is * (multiply) not / (divide) and the program is run?
  8. x is 1.7e308, y is 1.7e308, {$FINITEFLOAT ON} and the operation is * (multiply) not / (divide) and the program is run?
  9. 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.

Published Mon, 10 May 2004 @ 7:00 AM by chuacw
Related articles:

Comments (Will be reviewed before being published)

# re: Undocumented Delphi 8 compiler directive FINITEFLOAT

Monday, May 10, 2004 7:00 PM by chuacw

Hi,

> consider using {$FINITEFLOAT OFF}. This is the default.

This can be misunderstood - the default is {$FINITEFLOAT ON} - as you say in the top table.

# re: Undocumented Delphi 8 compiler directive FINITEFLOAT

Monday, May 10, 2004 11:10 PM by chuacw

Thanks for your feedback, Hallvard. I have updated the article accordingly.

I am a poor writer, and I hope you will continue to provide any guidance if you deem it necessary.