• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

[转]HowtosetthecontrolwordofFPUindelphi

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

      On systems based on the IA-32 architecture, the FPU control word includes bits that control the FPU's precision, rounding mode, and whether exceptions generate signals if they occur, if you want to know more, please refer Floating-point Control Word Overview.

     In delphi, it provide us two function named “Set8087CW” and “Get8087CW” to set and read the control word of FPU. Function Set8087CW sets both the control word in the floating-point unit and the variable System.NoErrMsg declared in the system unit. The floating-point unit control word controls the precision of floating-point calculations, the rounding mode, and whether certain floating-point operations trigger exceptions. See the Intel processor documentation for details.

This routine allows you to have direct access to the CW. Be aware that using this routine to change the value of the 8087CW changes the behavior of the program's FP calculations. To avoid this, reset it.

It is  recommend that you disable all floating-point exceptions when using OpenGL to render 3D graphics. To do this, call Set8087CW(0x133f) in your main form's OnCreate event before calling any OpenGL functions.

Following is the example:

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;

 

注:本文来自:http://www.neugls.info


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi中调用JS文件中的方法发布时间:2022-07-18
下一篇:
你想要的CSO算法matlab实现发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap