RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
System.Default8087CW Variable

Specifies the Default 8087 control word.

Pascal
Default8087CW: Word = $1332;
C++
Word Default8087CW = 0x1332;

Default8087CW is the value to which the Floating Point Unit (FPU) control register is set. The FPU control word includes bits that control the FPU's precision, rounding mode, and whether exceptions generate signals if they occur. See Intel's processor documentation for details. 

The Set8087CW procedure allows the programmer to have direct access to the Default8087CW. Setting the floating-point precision and rounding mechanism can be useful if you are reusing old code that is sensitive to the floating-point precision standard used. However, be aware that using this procedure to change the value of the 8087CW will change the behavior of the program's FP calculations. It is the programmer's responsibility to reset it.  

C++ Examples: 

 

/*
This example accesses the Floating Point Unit (FPU) control
register.  Try turning floating point exceptions off and on
and dividing a number by zero to test it.
*/
Word Saved8087CW;

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Edit3->Text = FloatToStr(StrToFloat(Edit1->Text) / StrToFloat(Edit2->Text));
}

void __fastcall TForm1::RadioGroup1Click(TObject *Sender)
{
  if (RadioGroup1->Items->Strings[RadioGroup1->ItemIndex] == "FPU Exceptions")
    System::Set8087CW(Saved8087CW);
  if (RadioGroup1->Items->Strings[RadioGroup1->ItemIndex] == "No FPU Exceptions")
    System::Set8087CW(0x133f); // Disable all fpu exceptions
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  RadioGroup1->Items->Add("No FPU Exceptions");
  RadioGroup1->Items->Add("FPU Exceptions");
  RadioGroup1->ItemIndex = 2;
  Saved8087CW = Default8087CW;  // Save this because Set8087CW changes it!
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
  System::Set8087CW(Saved8087CW); // Default value (with exceptions) is 0x1372
}

 

Delphi Examples: 

{
This example accesses the Floating Point Unit (FPU) control
register.  Try turning floating point exceptions off and on
and dividing a number by zero to test it.
}
var
  Form1: TForm1;
  Saved8087CW: Word;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit3.Text := FloatToStr(StrToFloat(Edit1.Text) / StrToFloat(Edit2.Text));
end;

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
  if RadioGroup1.Items[RadioGroup1.ItemIndex] = 'FPU Exceptions' then
    System.Set8087CW(Saved8087CW);
  if RadioGroup1.Items[RadioGroup1.ItemIndex] = 'No FPU Exceptions' then
    System.Set8087CW($133f); { Disable all fpu exceptions }
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RadioGroup1.Items.Add('No FPU Exceptions');
  RadioGroup1.Items.Add('FPU Exceptions');
  RadioGroup1.ItemIndex := 2;
  Saved8087CW := Default8087CW;  // Save this because Set8087CW changes it!
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  System.Set8087CW(Saved8087CW); // Default value (with exceptions) is $1372
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!