Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ matherr(3M) — Interactive 2.2

Media Vault

Software Library

Restoration Projects

Artifacts Sought



          MATHERR(3M)          INTERACTIVE UNIX System          MATHERR(3M)



          NAME
               matherr - error-handling function

          SYNOPSIS
               #include <math.h>

               int matherr (x)
               struct exception *x;

          DESCRIPTION
               The matherr function is invoked by functions in the Math
               Library when errors are detected.  Users may define their
               own procedures for handling errors by including a function
               named matherr in their programs.  The matherr function must
               be of the form described above.  When an error occurs, a
               pointer to the exception structure x will be passed to the
               user-supplied matherr function.  This structure, which is
               defined in the <math.h> header file, is as follows:

                    struct exception {
                         int type;
                         char *name;
                         double arg1, arg2, retval;
                    };

               The element type is an integer describing the type of error
               that has occurred, from the following list of constants
               (defined in the header file):

                    DOMAIN     argument domain error
                    SING       argument singularity
                    OVERFLOW   overflow range error
                    UNDERFLOW  underflow range error
                    TLOSS      total loss of significance
                    PLOSS      partial loss of significance

               The element name points to a string containing the name of
               the function that incurred the error.  The variables arg1
               and arg2 are the arguments with which the function was
               invoked.  Retval is set to the default value that will be
               returned by the function unless the user's matherr sets it
               to a different value.

               If the user's matherr function returns non-zero, no error
               message will be printed, and errno will not be set.

               If matherr is not supplied by the user, the default error-
               handling procedures, described with the math functions
               involved, will be invoked upon error.  These procedures are
               also summarized in the table below.  In every case, errno is
               set to EDOM or ERANGE and the program continues.




          Rev. C Software Development Set                            Page 1





          MATHERR(3M)          INTERACTIVE UNIX System          MATHERR(3M)



          EXAMPLE
          #include <math.h>

          int
          matherr(x)
          register struct exception *x;
          {
               switch (x->type) {
               case DOMAIN:
                    /* change sqrt to return sqrt(-arg1), not 0 */
                    if (!strcmp(x->name, "sqrt")) {
                         x->retval = sqrt(-x->arg1);
                         return (0); /* print message and set errno */
                    }
               case SING:
                    /* all other domain or sing errors, print message and abort */
                    fprintf(stderr, "domain error in %s\n", x->name);
                    abort( );
               case PLOSS:
                    /* print detailed error message */
                    fprintf(stderr, "loss of significance in %s(%g) = %g\n",
                         x->name, x->arg1, x->retval);
                    return (1); /* take no other action */
               }
               return (0); /* all other errors, execute default procedure */
          }

          __________________________________________________________________
         |                DEFAULT ERROR HANDLING PROCEDURES                |
         |______________________|__________________________________________|
         |______________________|__________________________________________|
         |                      |              Types of Errors             |
         |______________________|_____|_____|________|_________|_____|_____|
         |______________________|_____|_____|________|_________|_____|_____|
         |         type         |DOMAIN
|
SING|OVERFLOW|UNDERFLOW|TLOSS|PLOSS| |______________________|_____|_____|________|_________|_____|_____| |______________________|_____|_____|________|_________|_____|_____| | errno | EDOM| EDOM| ERANGE | ERANGE |ERANGE
|
ERANGE
|
|______________________|_____|_____|________|_________|_____|_____| |______________________|_____|_____|________|_________|_____|_____| |BESSEL: | - | - | - | - | M, 0| * | |______________________|_____|_____|________|_________|_____|_____| |y0, y1, yn (arg < 0) |M, -H| - | - | - | - | - | |______________________|_____|_____|________|_________|_____|_____| |______________________|_____|_____|________|_________|_____|_____| |EXP: | - | - | H | 0 | - | - | |______________________|_____|_____|________|_________|_____|_____| |______________________|_____|_____|________|_________|_____|_____| |LOG, LOG10: | | | | | | | |______________________|_____|_____|________|_________|_____|_____| | (arg < 0) |M, -H| - | - | - | - | - | |______________________|_____|_____|________|_________|_____|_____| Rev. C Software Development Set Page 2


          MATHERR(3M)          INTERACTIVE UNIX System          MATHERR(3M)



         |______________________|_____|_____|________|_________|_____|_____|
         | (arg = 0)            |  -  |M, -H|    -   |    -    |  -  |  -  |
         |______________________|_____|_____|________|_________|_____|_____|
         |______________________|_____|_____|________|_________|_____|_____|
         |POW:                  |  -  |  -  |   +H   |    0    |  -  |  -  |
         |______________________|_____|_____|________|_________|_____|_____|
         |neg ** non-int        |M, 0 |  -  |    -   |    -    |  -  |  -  |
         |______________________|_____|_____|________|_________|_____|_____|
         |  0 ** non-pos        |     |     |        |         |     |     |
         |______________________|_____|_____|________|_________|_____|_____|
         |______________________|_____|_____|________|_________|_____|_____|
         |SQRT:                 | M, 0|  -  |    -   |    -    |  -  |  -  |
         |______________________|_____|_____|________|_________|_____|_____|
         |______________________|_____|_____|________|_________|_____|_____|
         |GAMMA:                |  -  | M, H|    H   |    -    |  -  |  -  |
         |______________________|_____|_____|________|_________|_____|_____|
         |______________________|_____|_____|________|_________|_____|_____|
         |HYPOT:                |  -  |  -  |    H   |    -    |  -  |  -  |
         |______________________|_____|_____|________|_________|_____|_____|
         |______________________|_____|_____|________|_________|_____|_____|
         |SINH:                 |  -  |  -  |   +H   |    -    |  -  |  -  |
         |______________________|_____|_____|________|_________|_____|_____|
         |______________________|_____|_____|________|_________|_____|_____|
         |COSH:                 |  -  |  -  |    H   |    -    |  -  |  -  |
         |______________________|_____|_____|________|_________|_____|_____|
         |______________________|_____|_____|________|_________|_____|_____|
         |SIN, COS, TAN: -      |  -  |  -  |    -   |   M, 0  |  *  |     |
         |______________________|_____|_____|________|_________|_____|_____|
         |______________________|_____|_____|________|_________|_____|_____|
         |ASIN, ACOS, ATAN2: M, 0
|
- | - | - | - | - | | |______________________|_____|_____|________|_________|_____|_____| ABBREVIATIONS: * As much as possible of the value is returned. M Message is printed (EDOM error). H HUGE is returned. -H -HUGE is returned. +H HUGE or -HUGE is returned. 0 0 is returned. Rev. C Software Development Set Page 3

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026