开启/关闭浮点数异常报错

ZC: Delphi7 中的报错信息为(主要信息):"Invalid floating point operation"

 

1、http://bbs.csdn.net/topics/391070674  (LongWord($133f)这句是什么意思-CSDN论坛.html)

  2楼:

这个应该用_control87或者_controlfp
#include <float.h>
_control87(0x133f, 0xffff);
至于LongWord($133f)这是没有什么意义的,LongWord($133f)=$0000133f,32位无符号整数,仅此而已。

  4楼:

// Default value (with exceptions) is 0x1372.这个注释是错的,默认值是0x1332。
Set8087CW是Delphi RTL函数,C++中最好还是用_control87或者_controlfp。

 

2、官方资料:

  2.1、Set8087CW (C++) - RAD Studio Code Examples.html  (http://docwiki.embarcadero.com/CodeExamples/XE8/en/Set8087CW_%28C%2B%2B%29

 

Description

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.

 

Code

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. }   __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { 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. }

Uses

See Also

 

3、

4、

5、

 

转载于:https://www.cnblogs.com/CodeSkill/p/8092802.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值