|
|
In the header <fenv.h>, C99 declares functions that access the floating-point environment. These functions are shown in the following table:
Function | Description |
---|---|
void feclearexcept(int ex); | Clears the exceptions specified by ex. |
void fegetexceptflag(fexcept_t *fptr, | The state of the floating-point exception flags specified by ex are stored in the variable pointed to by fptr. |
void feraiseexcept(int ex); | Raises the exceptions specified by ex. |
void fesetexceptflag(const fexcept_t *fptr, | Sets the floating-point status flags specified by ex to the state of the flags in the object pointed to by fptr. |
int fetestexcept(int ex); | Bitwise ORs the exceptions specified in ex with the current floating-point status flags and returns the result. |
int fegetround(void); | Returns a value that indicates the current rounding direction. |
int fesetround(int direction); | Sets the current rounding direction to that specified by direction. A return value of zero indicates success. |
void fegetenv(fenv_t *envptr); | The object pointed to by envptr receives the floating-point environment. |
int feholdexcept(fenv_t *envptr); | Causes nonstop floating-point exception handling to be used. It also stores the floating-point environment in the variable pointed to by envptr and clears the status flags. It returns zero if successful. |
void fesetenv(const fenv_t *envptr); | Sets the floating-point environment to that pointed to by envptr, but does not raise floating-point exceptions. This object must have been obtained by calling either fegetenv( ) or feholdexcept( ). |
void feupdateenv(const fenv_t *envptr); | Sets the floating-point environment to that pointed to by envptr. It first saves any current exceptions, and raises these exceptions after the environment pointed to by envptr has been set. The object pointed to by envptr must have been obtained by calling either fegetenv( ) or feholdexcept( ). |
The <fenv.h> header also defines the types fenv_t and fexcept_t, which represent the floating-point environment and the floating-point status flags, respectively. The macro FE_DFL_ENV specifies a pointer to the default floating-point environment defined at the start of program execution.
The following floating-point exception macros are defined:
FE_DIVBYZERO | FE_INEXACT | FE_INVALID |
---|---|---|
FE_OVERFLOW | FE_UNDERFLOW | FE_ALL_EXCEPT |
Any combination of these macros can be stored in an int object by ORing them together.
The following rounding-direction macros are defined:
FE_DOWNWARD | FE_TONEAREST | FE_TOWARDZERO | FE_UPWARD |
These macros indicate the method that is used to round values.
In order for the floating-point environment flags to be tested, the pragma FENV_ACCESS will need to be set to the on position. Whether floating-point flag access is on or off by default is implementation-defined.
|
|