问题
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