Floating Point Operation Exception Masks

From RAD Studio
Jump to: navigation, search

From RAD Studio Athens (R120), all of the floating-point-related exception masks will be turned ON. The applications will no longer raise Floating Point exceptions on all platforms as default.

The default behavior of Delphi RTL is to disable all floating-point-related exceptions.

Platform Control variable name in System since 11.3 after 12.0
Win/x32 Default8087CW $1332 $033F
Win/x64 DefaultMXCSR $1900 $1F80
macOS/x64 DefaultFPEnv $0032 $003F
macOS/Arm64 DefaultFPSCR $0000_0700 $0000_0000
iOS/Arm64 DefaultFPSCR $0000_0700 $0000_0000
iOS-Sim/Arm64 DefaultFPSCR $0000_0700 $0000_0000
Android/Arm32 DefaultFPSCR $0000_0700 $0000_0000
Android/Arm64 DefaultFPSCR $0000_0700 $0000_0000
Linux/x64 DefaultFPEnv $0032 $003F

Old and New behavior table

Platform Program Type Old Behavior New Behavior
1/0 sqrt (-1) 1/0 sqrt (-1)
Win/x32

Win/x64

Default / Console / VCL EZeroDivide exception [1]

The result is undefined.

EInvalidOp exception [1]

The result is undefined.

No exception

The result is Inf

No exception

The result is NAN

Win/x32

Win/x64

FMX No exception [2]

The result is Inf

No exception [2]

The result is NAN

No exception

The result is Inf

No exception

NAN

macOS/x64 FMX/Console No exception

The result is Inf

EInvalidOp exception

The result is undefined.

No exception

The result is Inf

No exception

The result is NAN

macOS/Arm64 FMX/Console No exception

The result is Inf

No exception [3]

The result is NAN

No exception

The result is Inf

No exception

The result is NAN

iOS/Arm64 FMX No exception

The result is Inf

EInvalidOp exception

The result is undefined.

No exception

The result is Inf

No exception

The result is NAN

iOS-Sim/Arm64 FMX No exception

The result is Inf

EInvalidOp exception

The result is undefined.

No exception

The result is Inf

No exception

The result is NAN

Android/Arm32 FMX No exception

The result is Inf

EInvalidOp exception

The result is undefined.

No exception

The result is Inf

No exception

The result is NAN

Android/Arm64 FMX No exception

The result is Inf

EInvalidOp exception

The result is undefined.

No exception

The result is Inf

No exception

The result is NAN

Linux/x64 Console No exception

The result is Inf

EInvalidOp exception

The result is undefined.

No exception

The result is Inf

No exception

The result is NAN

  1. 1.0 1.1 Depended on which units/components are used. If the application uses OpenGL, the application masks all exceptions.
  2. 2.0 2.1 All exceptions are already disabled. System.Win.InternetExplorer masks all exceptions. A fundamental FMX.Platform.Win uses this unit.
  3. This result is a bug! Both x64 and Arm64 macOS have to have the same behavior.

How to Restore Old Behavior

If you want to revert the exception behavior to the previous one, call SetExceptionMask in System.Math with the following options into the application's main source block ( Usually, .DPR file )

System.math.SetExceptionMask( [exPrecision, exUnderflow, exDenormalized]); // Enable exInvalidOp, exZeroDivide, and exOverflow exceptions

For example:

uses
  System.Math, // Add System.Math unit
  <span class="glossaryTerm">Vcl<span class="tooltip"><p>Visual Component Library</p></span></span>.Forms,
  Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
  System.math.SetExceptionMask( [exPrecision, exUnderflow, exDenormalized]); // Add this line.
  Application.Initialize;.

Topics

See Also