Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ matherr(3M) — bsd — Apollo Domain/OS SR10.4.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

asinh(3M)

cc(1)

exp(3M)

floor(3M)

frexp(3)

ieee(3M)

sin(3M)

sinh(3M)

sqrt(3M)

MATHERR(3M)                          BSD                           MATHERR(3M)



NAME
     matherr - error-handling function

SYNOPSIS
     #include <math.h>

     int matherr (x)
     struct exception *x;

DESCRIPTION
     matherr is invoked by functions in the Math Library when errors are
     detected.  Which matherr function your program invokes depends upon the
     startup routine to which you link it.

     You may define your own procedure for handling errors by including a
     function named matherr in your program and linking it to /usr/lib/crt0.o
     or to /usr/apollo/lib/svid/crt0.o.  You must either compile your program
     with the -A nansi option to cc(1), or make sure it contains one of the
     following directives (listed in order of increasing restrictiveness)
     before any #include directive:

          #define _APOLLO_SOURCE
          #define _SYS5_SOURCE

     matherr 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;
               double arg2;
               double retval;
          };

     The element type is an integer describing the type of error that has
     occurred.  It is taken from 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 your matherr sets it to a
     different value.

     Linking your program to /usr/lib/crt0.o causes the math functions to
     behave according to the common C semantics documented in their respective
     manual pages.  In this case, if your matherr function returns zero, an
     error message will be printed, and errno will be set.

     If you link your program to /usr/apollo/lib/crt0.o (the default),
     Domain/OS calls its own matherr function and ignores any your program may
     contain.  In this case, and in the case where you link your program to
     /usr/apollo/lib/svid/crt0.o without defining your own matherr function,
     the math functions invoke the default error-handling procedures,
     described in their respective manual pages.  These procedures are also
     summarized in the table below.  In every case, errno is set to EDOM or
     ERANGE and the program continues.

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:______________|__-_____|_-___|____-______|____-______|__0_____|__*____|
|y0, y1, yn (arg < 0) | -H     | -   |    -      |    -      |  -     |  -    |
||||||||
|EXP:                 |  -     | -   |    H      |    0      |  -     |  -    |
||||||||
|LOG, LOG10:          |        |     |           |           |        |       |
|_____________________|________|_____|___________|___________|________|_______|
|_(arg_<_0)___________|__-H____|_-___|____-______|____-______|__-_____|__-____|
| (arg = 0)           |  -     |-H   |    -      |    -      |  -     |  -    |
||||||||
|POW:                 |  -     | -   |   +H      |    0      |  -     |  -    |
|_____________________|________|_____|___________|___________|________|_______|
|neg_**_non-int_______|__0_____|_-___|____-______|____-______|__-_____|__-____|
|  0 ** non-pos       |        |     |           |           |        |       |
||||||||
|SQRT:                |  0     | -   |    -      |    -      |  -     |  -    |
||||||||
|GAMMA:               |  -     | H   |    H      |    -      |  -     |  -    |
||||||||
|HYPOT:               |  -     | -   |    H      |    -      |  -     |  -    |
||||||||
|SINH:                |  -     | -   |   +H      |    -      |  -     |  -    |
||||||||
|COSH:                |  -     | -   |    H      |    -      |  -     |  -    |
||||||||
|SIN, COS, TAN:       |  -     | -   |    -      |    -      |  0     |  *    |
||||||||
|ASIN, ACOS, ATAN2:   |  0     | -   |    -      |    -      |  -     |  -    |
|_____________________|________|_____|___________|___________|________|_______|
     _____________________________________________________
     |                   ABBREVIATIONS                    |
     | *    As much as possible of the value is returned. |
     | H    HUGE_VAL is returned.                         |
     | -H   -HUGE_VAL is returned.                        |
     | +H   HUGE_VAL or -HUGE_VAL is returned.            |
     | 0    0 is returned.                                |
     |____________________________________________________|

SEE ALSO
     asinh(3M), cc(1), exp(3M), floor(3M), frexp(3), ieee(3M), sin(3M),
     sinh(3M), sqrt(3M)

NOTES
     If you require the HUGE macro to be a compile-time constant, add the
     directive

          #define _CLASSIC_HUGE

     before any #include directives.  Programs compiled with _CLASSIC_HUGE are
     forward-compatible only if linked with /usr/lib/crt0.o.

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