Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ matherr(3M) — IRIX 6.5.3f

Media Vault

Software Library

Restoration Projects

Artifacts Sought



MATHERR(3M)                                                        MATHERR(3M)



NAME
     matherr - error-handling function

SYNOPSIS
     #include <math.h>

     int matherr (struct exception *x);

DESCRIPTION
     matherr is invoked by the following functions in libmx.a when errors are
     detected:

     acos acosf acosh asin asinf asinh atan atanf atan2 atan2f atanh cbrt cos
     cosf cosh coshf drem erf erfc
     exp expf expm1 expm1f fmod fmodf gamma hypot hypotf j0 j1 jn lgamma log
     logf log10 log10f log1p log1pf
     pow powf sin sinf sinh sinhf sqrt sqrtf tan tanf tanh tanhf y0 y1 yn

     Note that to use matherr, libmx.a needs to be linked with the program.
     Users may define their own routines 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 math.h):

          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 elements 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.

     NaN argument(s) to any of the above functions generates a call to matherr
     with a domain error.





                                                                        Page 1





MATHERR(3M)                                                        MATHERR(3M)



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

     If matherr is not supplied by the user, the default error-handling
     procedures, described by the table below, will be invoked upon error.  In
     every case, errno is set to EDOM or ERANGE and the program continues.

















































                                                                        Page 2





MATHERR(3M)                                                        MATHERR(3M)



_______________________________________________________________________________
|                     Default Error Handling Procedures                       |
|_____________________________________________________________________________|
|
| Types of Errors |
|
|_____________________________________________________________________________|
| | | | | |
| type DOMAIN SING OVERFLOW UNDERFLOW TLOSS PLOSS |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
| errno EDOM EDOM ERANGE ERANGE ERANGE ERANGE |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|EXP, EXPF: - - M, H M, 0 - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|EXPM1, EXPM1F: - - M, H M, 0 - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|LOG, LOGF: |
| | | | | |
|LOG10, LOG10F: |
| | | | | |
| (arg < 0) M, N - - - - - |
| | | | | |
| (arg = 0) M, -H - - - - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|LOG1P, LOG1PF: |
| | | | | |
| (arg < -1) M, N - - - - - |
| | | | | |
| (arg = -1) M, -H - - - - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|POW, POWF: - - +H 0 - - |
| | | | | |
|neg ** non-int M, 0 - - - - - |
| | | | | |
| 0 ** non-pos M, H - - - - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|SQRT, SQRTF: M, N - - - - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|DREM, FMOD, FMODF: |
| | | | | |
| (arg1 = +/-inf M, N - - - - - |
| | | | | |
| or arg2 = 0) |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|GAMMA, LGAMMA: - M, H M, H - - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|J0, J1, JN: - - - - M, 0 - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|Y0, Y1, YN: |
| | | | | |
| (arg = 0) - - M, -H - - - |
| | | | | |
| (arg < 0) M, N - - - - - |
| | | | | |
| (arg >= 2**49) - - - - M, 0 - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|SINH, SINHF: - - +H - - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|COSH, COSHF: - - H - - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|HYPOT, HYPOTF: - - M, H - - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|ASIN, ASINF: |
| | | | | |
|ACOS, ACOSF: M, N - - - - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|____________________|________|______|__________|___________|________|________|
Page 3


MATHERR(3M)                                                        MATHERR(3M)



|SIN, COS, TAN:                                                               |
| | | | | |
| (arg >= 2**50) M, N - - - - - |
| | | | | |
| (arg = +/-inf) - - - - M, 0 - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|SINF, COSF, TANF: |
| | | | | |
| (arg >= 2**22) M, N - - - - - |
| | | | | |
| (arg = +/-inf) - - - - M, 0 - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|ATAN2, ATAN2F: M, 0 - - - - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|ACOSH: M, N - - - - - |
| | | | | |
|_____________________________________________________________________________|
| | | | | |
|ATANH: |
| | | | | |
| (|arg| > 1) M, N - - - - - |
| | | | | |
|____________________|________|______|__________|___________|________|________|
______________________________________________________________________________ | Abbreviations | | M Message is printed | | H HUGE is returned | | -H -HUGE is returned | | +H HUGE or -HUGE is returned. | | 0 0 is returned. | | X arg1 is returned. | | N NaN is returned. | |_____________________________________________________________________________| Page 4


MATHERR(3M)                                                        MATHERR(3M)



EXAMPLE
     /*
     ** Example showing the use of libmx.a's matherr() to handle math errors.
     **
     **  % cc -xansi my_matherr.c -lmx
     **  % a.out
     **  overflow range error in logf
     **  logf(0.0) is -inf.
     **
     **  expf failed: Argument out of domain
     **  Abort (core dumped)
     */

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

     main()
     {
     float ff;

        ff = logf(0.0f);  /* matherr() leaves error reporting to libmx.a */
        printf("logf(0.0f) is %f.\n\n",ff);
        fflush(stdout);

        ff = 0.0f;
        ff = 0.0f/ff;
        ff = expf(ff);  /* matherr() customized to force a core dump */
     }

     int matherr( register struct exception *x )
     {
     char *sterr;

        switch (x->type) {

        case DOMAIN:
           /* if it's a NaN, abort */

           if ( isnan(x->arg1) )
           {
                  sterr = strerror(EDOM);
                  fprintf(stderr, "%s failed: %s\n", x->name, sterr);
                  abort();
           }
           else if ( !strcmp(x->name, "sin") )
           {
                  x->retval = 0.0;   /* return 0.0 */
                  fprintf(stderr, "domain error in sin\n");




                                                                        Page 5





MATHERR(3M)                                                        MATHERR(3M)



                 return (1); /* suppress libmx.a error message and setting of errno */
           }
           else
                  return (0); /* libmx.a prints error message and sets errno */
        break;

        default:
           return (0);    /* libmx.a prints error message and sets errno */
        }
     }

NOTES
     Errors detected by functions in libm.a can be detected by examining the
     return value and/or the global variable errno.  libmx.a is provided as an
     alternative error handling scheme for users who want to identify specific
     kinds of errors determined by libm functions without extensive
     modification of their source code.

     No extra overhead is incurred by programs using libmx.a if no error
     conditions are encountered in the libmx routines.



































                                                                        Page 6



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