Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with 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,
    calling matherr() and processing that routine's return value.

    _matherr() is called with several arguments and does the following
    four things:

            (1)     Fills out an 'exception' structure using its
                    arguments.  The 'exception' structure is defined in
                    <math.h> and has the 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)     Tries to resolve the error by calling mather() with
                    'e', which is a pointer to the 'exception' structure.

            (3)     Examines the return value from matherr():

                    If matherr() returns 0, the error was not resolved by
                    matherr(). In this case, _matherr() sets 'errno'
                    (defined in <errno.h>), mapping the error type onto
                    either the EDOM or ERANGE 'errno' value, and prints
                    an error message.

                    If matherr() returns non-zero, the error was resolved
                    by matherr(). In this case, _matherr neither sets
                    'errno' nor prints any error message.

            (4)     Returns 'e->retval' to the original caller. 'e-
                    >retval' might be modified by matherr() if a specific
                    value needs to be sent back to the original caller.

       Returns:     'e->retval', which is initially the value of the
                    input parameter 'retval' that is passed to
                    _matherr(). As noted above, however, 'e->retval' may
                    be modified by matherr().

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

         Notes:     User programs should not call _matherr() directly.

See Also: matherr()

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