# FreeBSD Manual Pages

FENV(3) Linux Programmer's Manual FENV(3)NAMEfeclearexcept, fegetexceptflag, feraiseexcept, fesetexceptflag, fetes- texcept, fegetenv, fegetround, feholdexcept, fesetround, fesetenv, fe- updateenv, feenableexcept, fedisableexcept, fegetexcept - floating- point rounding and exception handlingSYNOPSIS#include<fenv.h>intfeclearexcept(intexcepts);intfegetexceptflag(fexcept_t*flagp,intexcepts);intferaiseexcept(intexcepts);intfesetexceptflag(constfexcept_t*flagp,intexcepts);intfetestexcept(intexcepts);intfegetround(void);intfesetround(introunding_mode);intfegetenv(fenv_t*envp);intfeholdexcept(fenv_t*envp);intfesetenv(constfenv_t*envp);intfeupdateenv(constfenv_t*envp);Link with-lm.DESCRIPTIONThese eleven functions were defined in C99, and describe the handling of floating-point rounding and exceptions (overflow, zero-divide, etc.).ExceptionsThedivide-by-zeroexception occurs when an operation on finite numbers produces infinity as exact answer. Theoverflowexception 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. Theunderflowexception 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). Theinexactexception occurs when the rounded result of an operation is not equal to the infinite precision result. It may occur wheneveroverfloworunderflowoccurs. Theinvalidexception occurs when there is no well-defined result for an operation, as for 0/0 or infinity - infinity or sqrt(-1).ExceptionhandlingExceptions are represented in two ways: as a single bit (exception present/absent), and these bits correspond in some implementation-de- fined way with bit positions in an integer, and also as an opaque structure that may contain more information about the exception (per- haps the code address where it occurred). Each of the macrosFE_DIVBYZERO,FE_INEXACT,FE_INVALID,FE_OVERFLOW,FE_UNDERFLOWis 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, for example, using the integer argumentFE_OVERFLOW|FE_UNDERFLOW. Other exceptions may be supported. The macroFE_ALL_EXCEPTis the bitwise OR of all bits corresponding to supported exceptions. Thefeclearexcept() function clears the supported exceptions repre- sented by the bits in its argument. Thefegetexceptflag() function stores a representation of the state of the exception flags represented by the argumentexceptsin the opaque object*flagp. Theferaiseexcept() function raises the supported exceptions repre- sented by the bits inexcepts. Thefesetexceptflag() function sets the complete status for the excep- tions represented byexceptsto the value*flagp. This value must have been obtained by an earlier call offegetexceptflag() with a last argu- ment that contained all bits inexcepts. Thefetestexcept() function returns a word in which the bits are set that were set in the argumentexceptsand for which the corresponding exception is currently set.RoundingmodeThe rounding mode determines how the result of floating-point opera- tions is treated when the result cannot be exactly represented in the significand. Various rounding modes may be provided: round to nearest (the default), round up (toward positive infinity), round down (toward negative infinity), and round toward zero. Each of the macrosFE_TONEAREST,FE_UPWARD,FE_DOWNWARD, andFE_TO-WARDZEROis defined when the implementation supports getting and set- ting the corresponding rounding direction. Thefegetround() function returns the macro corresponding to the cur- rent rounding mode. Thefesetround() function sets the rounding mode as specified by its argument and returns zero when it was successful. C99 and POSIX.1-2008 specify an identifier,FLT_ROUNDS, defined in _float.h_, which indicates the implementation-defined rounding behavior for floating-point addition. This identifier has one of the following values: -1 The rounding mode is not determinable. 0 Rounding is toward 0. 1 Rounding is toward nearest number. 2 Rounding is toward positive infinity. 3 Rounding is toward negative infinity. Other values represent machine-dependent, nonstandard rounding modes. The value ofFLT_ROUNDSshould reflect the current rounding mode as set byfesetround() (but see BUGS).Floating-pointenvironmentThe entire floating-point environment, including control modes and sta- tus flags, can be handled as one opaque object, of typefenv_t. The default environment is denoted byFE_DFL_ENV(of typeconstfenv_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 nonstop (con- tinue on exceptions) mode. Thefegetenv() function saves the current floating-point environment in the object*envp. Thefeholdexcept() function does the same, then clears all exception flags, and sets a nonstop (continue on exceptions) mode, if available. It returns zero when successful. Thefesetenv() function restores the floating-point environment from the object*envp. This object must be known to be valid, for example, the result of a call tofegetenv() orfeholdexcept() or equal toFE_DFL_ENV. This call does not raise exceptions. Thefeupdateenv() function installs the floating-point environment rep- resented 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*envpmust be known to be valid.RETURN VALUEThese functions return zero on success and nonzero if an error oc- curred.VERSIONSThese functions first appeared in glibc in version 2.1.ATTRIBUTESMultithreading(seepthreads(7))Thefeclearexcept(),fegetexceptflag(),fegetexceptflag(),fesetexcept-flag(),fetestexcept(),fegetround(),fesetround(),fegetenv(),fehold-except(),fesetenv(),feupdateenv(),feenableexcept(),fedisableex-cept(), andfegetexcept() functions are thread-safe.CONFORMING TOIEC 60559 (IEC 559:1989), ANSI/IEEE 854, C99, POSIX.1-2001.NOTESGlibcnotesIf possible, the GNU C Library defines a macroFE_NOMASK_ENVwhich rep- resents an environment where every exception raised causes a trap to occur. You can test for this macro using#ifdef. It is defined only if _GNU_SOURCEis defined. The C99 standard does not define a way to set individual bits in the floating-point mask, for example, to trap on specific flags. Since version 2.2, glibc supports the functionsfeen-ableexcept() andfedisableexcept() to set individual floating-point traps, andfegetexcept() to query the state.#define_GNU_SOURCE/* See feature_test_macros(7) */#include<fenv.h>intfeenableexcept(intexcepts);intfedisableexcept(intexcepts);intfegetexcept(void);Thefeenableexcept() andfedisableexcept() functions enable (disable) traps for each of the exceptions represented byexceptsand return the previous set of enabled exceptions when successful, and -1 otherwise. Thefegetexcept() function returns the set of all currently enabled ex- ceptions.BUGSC99 specifies that the value ofFLT_ROUNDSshould reflect changes to the current rounding mode, as set byfesetround(). Currently, this does not occur:FLT_ROUNDSalways has the value 1.SEE ALSOmath_error(7)COLOPHONThis page is part of release 3.74 of the Linuxman-pagesproject. A description of the project, information about reporting bugs, and the latest version of this page, can be found at http://www.kernel.org/doc/man-pages/. Linux 2014-04-01 FENV(3)

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | VERSIONS | ATTRIBUTES | CONFORMING TO | NOTES | BUGS | SEE ALSO | COLOPHON

Want to link to this manual page? Use this URL:

<https://www.freebsd.org/cgi/man.cgi?query=fenv&sektion=3&manpath=Debian+8.1.0>