Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo C - <b>_matherr() floating-point error handling routine</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
_matherr()               Floating-Point Error Handling Routine

 #include   <math.h>

 double     _matherr(why,fun,arg1p,arg2p,retval);
 _mexcep    why;                         Constants representing math errors
 char       *fun;                        Math library function
 double     *arg1p;                      Argument that caused the error
 double     *arg2p;                      Argument that caused the error
 double     retval;                      Return value

    _matherr() processes errors generated by math library functions. It
    calls matherr() and processes the return value from matherr().
    _matherr() should never be called directly by user programs.

    Whenever an error occurs in one of the math library routines _matherr
    is called with several arguments.  _matherr() does four things:

         (1)    It uses its arguments to fill out an 'exception'
                structure.  The 'exception' structure (defined in
                <math.h>) has the following form:

                    struct exception  {
                        int type;               /* type of math error */
                        char *name;             /* name of math function */
                        double arg1,arg2;  /* arguments that caused errors */
                        double retval;          /* return value */
                    };

         (2)    It calls matherr() with 'e', a pointer to the 'exception'
                structure, to see if matherr() can resolve the error.

         (3)    It examines the return value from matherr() as follows:

                If matherr() returns 0, (indicating that matherr() was
                not able to resolve the error) _matherr() sets 'errno'
                (defined in <stdlib.h>).  It maps the kind of error that
                occurred onto an 'errno' value of either EDOM or ERANGE
                and prints an error message.

                If matherr() return non-zero, (indicating that matherr()
                was able to resolve the error) _matherr is silent; it
                does not set 'errno' or print any messages.

         (4)    It returns 'e->retval' to the original caller. matherr()
                might modify 'e->retval' to specify the value it wants
                propagated back to the original caller.

    Returns:    _matherr() returns the value, 'e->retval'.  This value is
                initially the value of the input parameter 'retval'
                passed to _matherr(), and might be modified by matherr().

                For math function results greater than MAXDOUBLE (defined
                in <values.h>), 'retval' defaults to the macro HUGE_VAL
                before being passed to _matherr().  For results less than
                MINDOUBLE (defined in <values.h>), 'retval' is set to 0,
                then passed to _matherr().  In both of these extremes, if
                matherr() does not not modify 'e->retval', _matherr()
                sets 'errno' to ERANGE (result out of range).

See Also: matherr()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson