linux use _clearfp(), _statusfp()

这里写代码片link
ou would need a POSIX system, or a C99 compiler that supported Annex F of the C99 Standard. You can test if Annex F is supported by checking if the macro STDC_IEC_559 is defined. The relevant functions would be found in

// crt_statusfp.c  
// Build by using: cl /W4 /Ox /nologo crt_statusfp.c  
// This program creates various floating-point errors and  
// then uses _statusfp to display messages that indicate these problems.  

#include <stdio.h>  
#include <float.h>
#include <fenv.h>
#pragma fenv_access(on)  

double test( void )  
{  
   double a = 1e-40;  
   float b;  
   double c;  

   printf("Status = 0x%.8x - clear\n", fetestexcept(FE_ALL_EXCEPT));  

   // Assignment into b is inexact & underflows:   
   b = (float)(a + 1e-40);  
   printf("Status = 0x%.8x - inexact, underflow\n", fetestexcept(FE_ALL_EXCEPT));  

   // c is denormal:   
   c = b / 0.0;   
   printf("Status = 0x%.8x - inexact, underflow, denormal\n",   
            fetestexcept(FE_ALL_EXCEPT));  

   float d = 1.0 + 2.0;
   printf("Status = 0x%.8x \n", fetestexcept(FE_ALL_EXCEPT));  
   // Clear floating point status:   
   feclearexcept(FE_ALL_EXCEPT); 
   printf("Status = 0x%.8x - clear\n", fetestexcept(FE_ALL_EXCEPT));  
   d = 1.0 + 2.0;
   printf("Status = 0x%.8x \n", fetestexcept(FE_ALL_EXCEPT));  

   feclearexcept(FE_ALL_EXCEPT); 
   printf("Status = 0x%.8x \n", fetestexcept(FE_ALL_EXCEPT));  
   return c;  
}  

int main(void)  
{  
   return (int)test();  
}  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值