FLOATENV(3M)FLOATENV(3M)


NAME
     feclearexcept, fegetexceptflag, fesetexceptflag, feraiseexcept,
     fetestexcept, fegetround, fesetround, fegetenv, feholdexcept,
     fesetenv, feupdateenv  - floating-point exceptions, rounding, and
     environment functions

SYNOPSIS
     #include <fenv.h>

     Floating-point status flags:

     void feclearexcept(int excepts);
     void fegetexceptflag(except_t *flagp, int excepts);
     void fesetexceptflag(const fexcept_t *flagp, int excepts);
     void feraiseexcept(int excepts);
     void fetestexcept(int excepts);

     Rounding:

     int fegetround(void);
     int fesetround(int round);

     Environment:

     void fegetenv(fenv_t *envp);
     int feholdexcept(fenv_t *envp);
     void fesetenv(const fenv_t *envp);
     void feupdateenv(const fenv_t *envp);

DESCRIPTION
     These routines are not available for programs compiled with the O32
     ABI.

     Functions in the standard math library (libm.a) are referred to as -lm
     versions. Those in mathx library (libmx.a) are referred to as -lmx
     versions.

FLOATING POINT STATUS FLAGS
     The floating point functions provide access to the floating-point
     status flags, which reside in the floating-point control status
     register of the MIPS floating-point units.  These are C99 functions
     which are intended to be hardware independent, and therefore portable
     between machines supporting IEEE-754 arithmetic.  The int input
     argument for the functions represents a subset of floating-point
     exceptions, and can be zero or the bitwise OR of one or more
     floating-point exception macros, for example, FE_OVERFLOW |
     FE_INEXACT. The floating-point exception macros are described in
     <fenv.h>.

     * feclearexcept clears the (hardware) floating-point exception flags
       represented by its argument. For example:

          feclearexcept(FE_UNDERFLOW | FE_OVERFLOW);

       This clears the underflow and overflow floating-point status flags.

     * fegetexceptflag stores the states of the (hardware) floating-point
       status flags indicated by the argument excepts in the object pointed
       to by the argument flagp in an implementation-defined
       representation.  For example:

          fexcept_t flag;
          fegetexceptflag(&flag, FE_OVERFLOW);

       This stores the state of the (hardware) floating-point overflow
       status flag in flag.  The only subsequent use of flag should be to
       restore one or more of the (hardware) floating-point status flags
       using fesetexceptflag.  (See below).

     * fesetexceptflag sets the (hardware) floating-point status flags
       indicated by the second argument to the states stored in the object
       pointed to by flagp.  The value of *flagp has been set by a previous
       call to fegetexceptflag whose second argument represented at least
       those floating-point exceptions represented by the argument excepts.
       This function does not raise floating-point exceptions, but only
       restores the state of the indicated flags.

       For example:

          fexcept_t flag;
          fegetexceptflag(&flag, FE_ALL_EXCEPT);
                 /* fetch current f-p status flags */
                  ...
          fesetexceptflag(&flag, FE_DIVBYZERO);
                 /* restore div-by-zero f-p status flag */

       This would first store the state of the 5 floating-point exception
       flags in flag, and later restore the original state of the divide-
       by-zero floating-point flag in the floating-point control status
       register.

     * feraiseexcept raises the floating-point exceptions represented by
       its argument.  This not only sets the corresponding floating-point
       (hardware) flags, but also generates floating-point traps for those
       exceptions which are enabled.

       For example,

          int     excepts;

          excepts = FE_OVERFLOW;
          feraiseexcept(excepts);

       Here, feraiseexcept raises the floating-point overflow exception.
       This sets the (hardware) floating-point overflow flag, and also
       generates a floating-point overflow exception trap if that trap is
       enabled.

     * fetestexcept determines which of a specified subset of the
       floating-point exception flags are currently set.  The excepts
       argument specifies the floating point status flags to be queried.
       The fetestexcept function returns the bitwise OR of the floating
       point-exception macros corresponding to the currently set floating-
       point exceptions included in excepts.  For example:

          int     flags;

          flags = fetestexcept(FE_UNDERFLOW | FE_OVERFLOW);
          if ( flags & FE_UNDERFLOW )
                /* underflow flag was set */
          else if ( flags & FE_OVERFLOW */
               /* overflow flag was set */

       This sets flags to indicate if either or both of the hardware
       floating-point underflow and overflow flags are currently set, and
       subsequently tests which, if either of the underflow or overflow
       flags was set at the time of the first function call.

ROUNDING
     Two functions are provided to manage the rounding direction mode in
     the floating-point control status register.  These functions are
     intended to be hardware independent, and therefore portable between
     machines supporting IEEE-754 arithmetic.  The floating-point rounding
     direction mode macros are described in <fenv.h>.

     * fegetround returns the value of the rounding direction macro
       representing the current rounding direction or a negative value if
       there is no such rounding direction macro or the current rounding
       direction is not determinable.

     * The fesetround function sets the hardware rounding direction mode
       represented by its argument.  If the argument is not equal to the
       value of a rounding direction macro, the rounding direction is not
       changed.  fesetround returns a zero value if and only if the
       requested rounding mode was established.

ENVIRONMENT
     The functions in this section manage the floating-point environment
     (the status flags and control modes) as one entity.

     * The fegetenv function stores the current floating-point environment
       (that is, the contents of the floating-point control status
       register) in the object pointed to by envp.

     * The feholdexcept function saves the current floating-point
       environment in the object pointed to by envp, clears the floating-
       point status flags, and then installs a non-stop mode (continue on
       floating-point exceptions) for all floating-point exceptions.
       feholdexcept returns zero if and only if non-stop floating-point
       exception handling was successfully installed.

     * The fesetenv function establishes the floating-point environment
       represented by the object pointed to by envp. The envp argument
       should point to an object set by a call to fegetenv or feholdexcept,
       or equal a floating-point macro.  Note that fesetenv merely installs
       the state of the floating-point status flags represented through its
       argument, and does not raise these floating-point exceptions.

     * The feupdateenv function saves the (hardware) floating-point
       exception flags which are set, installs the floating-point
       environment represented by the object pointed to by envp, and then
       sets the hardware floating-point exception flags corresponding to
       the saved flags.  The envp argument should point to an object set by
       a call to feholdexcept or fegetenv.

NOTES
     Long double operations on this system are only supported in round to
     nearest rounding mode (the default).  The system must be in round to
     nearest rounding mode when calling any of the long double functions,
     or incorrect answers will result.

SEE ALSO
     math(3M)