69,382
社区成员
发帖
与我相关
我的任务
分享
#include <fpieee.h>
#include <excpt.h>
#include <float.h>
int fpieee_handler(_FPIEEE_RECORD *pieee)
{
if (pieee->Cause.Overflow == 1) { //处理溢出
return EXCEPTION_CONTINUE_EXECUTION;
} else {
return EXCEPTION_EXECUTE_HANDLER;
}
}
int main()
{
__try {
unsigned int u;
unsigned int control_word;
_controlfp_s(&control_word, 0, 0);
u = control_word & (~_EM_OVERFLOW);
_controlfp_s( &control_word, u, _MCW_EM);
//你的代码
}
__except (_fpieee_flt(GetExceptionCode(),
GetExceptionInformation(),
fpieee_handler)){
}
}
自己注意了
见过这样的
#include <iostream>
#include "float.h"
using namespace std;
int main()
{
float f = 0.f;
float d = -100.f / f;
if (d > FLT_MAX || d < FLT_MIN)
cout<<"error"<<endl;
return 0;
}