In Linux, do there exist functions similar to _clearfp() and _statusfp()?

倖福魔咒の 提交于 2019-12-22 09:46:29

问题


Recently, I am doing a job about porting. I encountered such a problem: Some Windows API, such as _clearfp(), _statusfp() etc, then I can't find the corresponding functions in Linux.

So I am here to ask for help.


回答1:


You 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 <fenv.h>.

int feclearexcept(int excepts); // clears exceptions (returns 0 on success)
int fetestexcept(int excepts);  // returns exceptions that are set

The exceptions passed in as excepts, and returned by fetestexcept, is a bitmask that can be test against the following macros:

FE_DIVBYZERO
FE_INEXACT
FE_INVALID
FE_OVERFLOW
FE_UNDERFLOW
FE_ALL_EXCEPT

The last macro, FE_ALL_EXCEPT, is just the bitwise-or of all the macros above it.



来源:https://stackoverflow.com/questions/16849009/in-linux-do-there-exist-functions-similar-to-clearfp-and-statusfp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!