Exception-Masken für Gleitkommaoperationen

Aus RAD Studio

Ab RAD Studio Athens (R120) sind alle Masken für Gleitkomma-Exceptions AKTIVIERT. Anwendungen lösen auf allen Plattformen standardmäßig keine Gleitkomma-Exceptions mehr aus.

Das Standardverhalten der Delphi-RTL ist die Deaktivierung aller Exceptions, die sich auf Gleitkommas beziehen.

Plattform Name der Steuervariable im System ab 11.3 nach 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

Tabelle zum alten und neuen Verhalten

Plattform Programmtyp Altes Verhalten Neues Verhalten
1/0 sqrt (-1) 1/0 sqrt (-1)
Win/x32

Win/x64

Standard/Konsole/VCL EZeroDivide-Exception [1]

Das Ergebnis ist nicht definiert.

EInvalidOp-Exception [1]

Das Ergebnis ist nicht definiert.

Keine Exception

Das Ergebnis ist Inf.

Keine Exception

Das Ergebnis ist NAN.

Win/x32

Win/x64

FMX Keine Exception [2]

Das Ergebnis ist Inf.

Keine Exception [2]

Das Ergebnis ist NAN.

Keine Exception

Das Ergebnis ist Inf.

Keine Exception

NAN

macOS/x64 FMX/Console Keine Exception

Das Ergebnis ist Inf.

EInvalidOp-Exception

Das Ergebnis ist nicht definiert.

Keine Exception

Das Ergebnis ist Inf.

Keine Exception

Das Ergebnis ist NAN.

macOS/Arm64 FMX/Console Keine Exception

Das Ergebnis ist Inf.

Keine Exception [3]

Das Ergebnis ist NAN.

Keine Exception

Das Ergebnis ist Inf.

Keine Exception

Das Ergebnis ist NAN.

iOS/Arm64 FMX Keine Exception

Das Ergebnis ist Inf.

EInvalidOp-Exception

Das Ergebnis ist nicht definiert.

Keine Exception

Das Ergebnis ist Inf.

Keine Exception

Das Ergebnis ist NAN.

iOS-Sim/Arm64 FMX Keine Exception

Das Ergebnis ist Inf.

EInvalidOp-Exception

Das Ergebnis ist nicht definiert.

Keine Exception

Das Ergebnis ist Inf.

Keine Exception

Das Ergebnis ist NAN.

Android/Arm32 FMX Keine Exception

Das Ergebnis ist Inf.

EInvalidOp-Exception

Das Ergebnis ist nicht definiert.

Keine Exception

Das Ergebnis ist Inf.

Keine Exception

Das Ergebnis ist NAN.

Android/Arm64 FMX Keine Exception

Das Ergebnis ist Inf.

EInvalidOp-Exception

Das Ergebnis ist nicht definiert.

Keine Exception

Das Ergebnis ist Inf.

Keine Exception

Das Ergebnis ist NAN.

Linux/x64 Konsole Keine Exception

Das Ergebnis ist Inf.

EInvalidOp-Exception

Das Ergebnis ist nicht definiert.

Keine Exception

Das Ergebnis ist Inf.

Keine Exception

Das Ergebnis ist NAN.

<references>

[1] [2] [3]

</references>

Altes Verhalten wiederherstellen

Wenn Sie das Exception-Verhalten auf das vorherige Verhalten zurücksetzen möchten, rufen Sie SetExceptionMask in System.Math mit den folgenden Optionen im Hauptquellblock der Anwendung auf (normalerweise die .DPR-Datei)

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

Zum Beispiel:

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;.

Themen

Siehe auch

  1. 1,0 1,1 1,2 Abhängig von den verwendeten Units/Komponenten. Wenn die Anwendung OpenGL verwendet, maskiert die Anwendung alle Exceptions.
  2. 2,0 2,1 2,2 Alle Exceptions sind bereits deaktiviert. System.Win.InternetExplorer maskiert alle Exceptions. Eine grundlegende FMX.Platform.Win verwendet diese Unit.
  3. 3,0 3,1 Dieses Ergebnis ist ein Fehler! x64 und Arm64 macOS müssen dasselbe Verhalten haben.