Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ matherr(3M) — svr4 — mips UMIPS RISC/os 5.01

Media Vault

Software Library

Restoration Projects

Artifacts Sought



MATHERR(3M-SVR4)    RISC/os Reference Manual     MATHERR(3M-SVR4)



NAME
     matherr - error-handling function

SYNOPSIS
     cc [flag ...] file ...  -lm [library ...]

     #include <math.h>

     int matherr (struct exception *x);

DESCRIPTION
     matherr is invoked by functions in the math libraries when
     errors are detected.  Note that matherr is not invoked when
     the -Xc compilation option is used.  Users may define their
     own procedures for handling errors, by including a function
     named matherr in their programs.  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, 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



                        Printed 11/19/92                   Page 1





MATHERR(3M-SVR4)    RISC/os Reference Manual     MATHERR(3M-SVR4)



     set to EDOM or ERANGE and the program continues.






















































 Page 2                 Printed 11/19/92





MATHERR(3M-SVR4)    RISC/os Reference Manual     MATHERR(3M-SVR4)



_________________________________________________________________
|_______________Default_Error_Handling_Procedures_______________|
|                   |              Types of Errors              |
|___________________|___________________________________________|
|_______type________|DOMAIN
|
_SING|OVERFLOW|UNDERFLOW|TLOSS|_PLOSS| | errno | EDOM| EDOM| ERANGE | ERANGE |ERANGE
|
ERANGE
|
|___________________|_____|_____|________|_________|_____|______| B
|
ESSEL: | - | - | - | - | M, 0| - | y
|
0,
_y1,_yn_(arg_<_0)|M,_-H|___-_|____-___|____-____|__-__|___-__| E
|
XP, EXPF: | - | - | H | 0 | - | - | |___________________|_____|_____|________|_________|_____|______| L
|
OG, LOG10: | | | | | | | L
|
OGF, LOG10F: | | | | | | | |(arg < 0) |M, -H| - | - | - | - | - | |(arg_=_0)__________|M,_-H|__-__|____-___|____-____|__-__|___-__| P
|
OW, POWF: | - | - | +H | 0 | - | - | n
|
eg ** non-int |M, 0 | - | - | - | - | - | | 0 ** non-pos | M, 0| - | - | - | - | - | |___________________|_____|_____|________|_________|_____|______| S
|
QRT,
_SQRTF:________|_M,_0|___-_|____-___|____-____|__-__|___-__| F
|
MOD, FMODF: | | | | | | | |(arg2 = 0) | M, X| - | - | - | - | - | |___________________|_____|_____|________|_________|_____|______| R
|
EMAINDER: | | | | | | | |(arg2_=_0)_________|_M,_N|___-_|____-___|____-____|__-__|___-__| G
|
AMMA, LGAMMA: | - | M, H| H | - | - | - | |___________________|_____|_____|________|_________|_____|______| H
|
YPOT:
______________|__-__|___-_|____H___|____-____|__-__|___-__| S
|
INH, SINHF: | - | - | +H | - | - | - | |___________________|_____|_____|________|_________|_____|______| C
|
OSH,
_COSHF:________|__-__|___-_|____H___|____-____|__-__|___-__| A
|
SIN, ACOS, ATAN2: | | | | | | | A
|
SINF, ACOSF, ATAN2F:
|
M, 0| - | - | - | - | - | |___________________|_____|_____|________|_________|_____|______| A
|
COSH:
______________|_M,_N|___-_|____-___|____-____|__-__|___-__| A
|
TANH: | | | | | | | |(|arg| > 1) | M, N| - | - | - | - | - | |(|arg| = 1) | - | M, N| - | - | - | - | |||||||| | Abbreviations | |M Message is printed (not with the -Xa or -Xc options). | |H HUGE is returned (HUGE_VAL with the -Xa or -Xc options). | |-H -HUGE is returned (-HUGE_VAL with the -Xa or -Xc options).| |+H HUGE or -HUGE is returned. | | (HUGE_VAL or -HUGE_VAL with the -Xa or -Xc options). | |0 0 is returned. | |X arg1 is returned. | |N NaN is returned. | |_______________________________________________________________| Printed 11/19/92 Page 3


MATHERR(3M-SVR4)    RISC/os Reference Manual     MATHERR(3M-SVR4)



EXAMPLE
     #include <math.h>
     #include <stdio.h>
     #include <stdlib.h>
     #include <string.h>

     int
     matherr(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 */
     }

NOTES
     Error handling in -Xa and -Xt modes [see cc(1)] is described
     more completely on individual math library pages.






















 Page 4                 Printed 11/19/92



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