Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
fetestexcept(3)
Edit
PageHistory
Diff
Info
LikePages
FENV !!!FENV NAME SYNOPSIS DESCRIPTION GNU DETAILS CONFORMING TO ---- !!NAME feclearexcept, fegetexceptflag, feraiseexcept, fesetexceptflag, fetestexcept, fegetenv, fegetround, feholdexcept, fesetround, fesetenv, feupdateenv - C99 floating point rounding and exception handling !!SYNOPSIS __#include __ ''excepts''__); void fegetexceptflag(fexcept_t *__''flagp''__, int__ ''excepts''__); void feraiseexcept(int__ ''excepts''__); void fesetexceptflag(const fexcept_t *__''flagp''__, int__ ''excepts''__); int fetestexcept(int__ ''excepts''__); int fegetround(void); int fesetround(int__ ''rounding_mode''__); void fegetenv(fenv_t *__''envp''__); int feholdexcept(fenv_t *__''envp''__); void fesetenv(const fenv_t *__''envp''__); void feupdateenv(const fenv_t *__''envp''__); __ !!DESCRIPTION These eleven functions were defined in C99, and describe the handling of floating point rounding and exceptions (overflow, zero-divide etc.). __Exceptions__ The !DivideByZero exception occurs when an operation on finite numbers produces infinity as exact answer. The Overflow exception occurs when a result has to be represented as a floating point number, but has (much) larger absolute value than the largest (finite) floating point number that is representable. The Underflow exception occurs when a result has to be represented as a floating point number, but has smaller absolute value than the smallest positive normalized floating point number (and would lose much accuracy when represented as a denormalized number). The Inexact exception occurs when the rounded result of an operation is not equal to the infinite precision result. It may occur whenever Overflow or Underflow occurs. The Invalid exception occurs when there is no well-defined result for an operation, as for 0/0 or infinity - infinity or sqrt(-1). __Exception handling__ Exceptions are represented in two ways: as a single bit (exception present/absent), and these bits correspond in some implementation-defined way with bit positions in an integer, and also as an opaque structure that may contain more information about the exception (perhaps the code address where it occurred). Each of the macros __FE_DIVBYZERO__, __FE_INEXACT__, __FE_INVALID__, __FE_OVERFLOW__, __FE_UNDERFLOW__ is defined when the implementation supports handling of the corresponding exception, and if so then defines the corresponding bit(s), so that one can call exception handling functions e.g. using the integer argument __FE_OVERFLOW__|__FE_UNDERFLOW__. Other exceptions may be supported. The macro __FE_ALL_EXCEPT__ is the bitwise OR of all bits corresponding to supported exceptions. The __feclearexcept__ function clears the supported exceptions represented by the bits in its argument. The __fegetexceptflag__ function stores a representation of the state of the exception flags represented by the argument ''excepts'' in the opaque object *''flagp''. The __feraiseexcept__ function raises the supported exceptions represented by the bits in ''excepts''. The __fesetexceptflag__ function sets the complete status for the exceptions represented by ''excepts'' to the value *''flagp''. This value must have been obtained by an earlier call of __fegetexceptflag__ with a last argument that contained all bits in ''excepts''. The __fetestexcept__ function returns a word in which the bits are set that were set in the argument ''excepts'' and for which the corresponding exception is currently set. __Rounding__ Each of the macros __FE_DOWNWARD__, __FE_TONEAREST__, __FE_TOWARDZERO__, __FE_UPWARD__ is defined when the implementation supports getting and setting the corresponding rounding direction. The __fegetround__ function returns the macro corresponding to the current rounding mode. The __fesetround__ function sets the rounding mode as specified by its argument and returns zero when it was successful. __Floating point environment__ The entire floating point environment, including control modes and status flags, can be handled as one opaque object, of type ''fenv_t''. The default environment is denoted by __FE_DFL_ENV__ (of type ''const fenv_t *''). This is the environment setup at program start and it is defined by ISO C to have round to nearest, all exceptions cleared and a non-stop (continue on exceptions) mode. The __fegetenv__ function saves the current floating point environment in the object *''envp''. The __feholdexcept__ function does the same, then clears all exception flags, and sets a non-stop (continue on exceptions) mode, if available. It returns zero when successful. The __fesetenv__ function restores the floating point environment from the object *''envp''. This object must be known to be valid, e.g., the result of a call to __fegetenv__ or __feholdexcept__ or equal to __FE_DFL_ENV__. This call does not raise exceptions. The __feupdateenv__ function installs the floating-point environment represented by the object *''envp'', except that currently raised exceptions are not cleared. After calling this function, the raised exceptions will be a bitwise OR of those previously set with those in *''envp''. As before, the object *''envp'' must be known to be valid. !!GNU DETAILS If possible, the GNU C Library defines a macro __FE_NOMASK_ENV__ which represents an environment where every exception raised causes a trap to occur. You can test for this macro using __#ifdef__. It is only defined if ___GNU_SOURCE__ is defined. The C99 standard does not define a way to set individual bits in the floating point mask, e.g. to trap on specific flags. glibc 2.2 will support the functions ''feenableexcept'' and ''fedisableexcept'' to set individual floating point traps, and ''fegetexcept'' to query the state. __int feenableexcept (int__ ''excepts''__); int fedisableexcept (int__ ''excepts''__); int fegetexcept (void); __The __feenableexcept__ and __fedisableexcept__ functions enable (disable) traps for each of the exceptions represented by ''excepts'' and return the previous set of enabled exceptions when successful, and -1 otherwise. The __fegetexcept__ function returns the set of all currently enabled exceptions. !!CONFORMING TO IEC 60559 (IEC 559:1989), ANSI/IEEE 854, ISO C99 (ISO/IEC 9899:1999). ----
One page links to
fetestexcept(3)
:
Man3f
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.