


      MATHERR(3M)		  (UNIX	5.0)		    MATHERR(3M)



      NAME
	   matherr - error-handling function

      SYNTAX
	   #include <math.h>

	   int matherr (x)
	   struct exception *x;

      DESCRIPTION
	   Matherr 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.  Matherr must be of the form	described
	   above.  A pointer to	the exception structure	x will be
	   passed to the user-supplied matherr function	when an	error
	   occurs.  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	   domain error
		SING	   singularity
		OVERFLOW   overflow
		UNDERFLOW  underflow
		TLOSS	   total loss of significance
		PLOSS	   partial loss	of significance

	   The element name points to a	string containing the name of
	   the function	that had the error.  The variables arg1	and
	   arg2	are the	arguments to the function that had the error.
	   Retval is a double that is returned by the function having
	   the error.  If it supplies a	return value, the user's
	   matherr must	return non-zero.  If the default error value is
	   to be returned, the user's matherr must return 0.

	   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 non-zero and the program continues.

      EXAMPLE
	   matherr(x)



      Page 1					     (73 A2 02MTA REV1)






      MATHERR(3M)		  (UNIX	5.0)		    MATHERR(3M)



	   register struct exception *x;
	   {
		switch (x->type) {
		case DOMAIN:
		case SING: /* print message and	abort */
		     fprintf(stderr, "domain error in %s\n", x->name);
		     abort( );
		case OVERFLOW:
		     if	(!strcmp("exp",	x->name)) {
			  /* if	exp, print message, return the argument	*/
			  fprintf(stderr, "exp of %f\n", x->arg1);
			  x->retval = x->arg1;
		     } else if (!strcmp("sinh",	x->name)) {
			  /* if	sinh, set errno, return	0 */
			  errno	= ERANGE;
			  x->retval = 0;
		     } else
			  /* otherwise,	return HUGE */
			  x->retval = HUGE;
		     break;
		case UNDERFLOW:
		     return (0); /* execute default procedure */
		case TLOSS:
		case PLOSS:
		     /*	print message and return 0 */
		     fprintf(stderr, "loss of significance in %s\n", x->name);
		     x->retval = 0;
		     break;
		}
		return (1);
	   }
























      Page 2					     (73 A2 02MTA REV1)






      MATHERR(3M)		  (UNIX	5.0)		    MATHERR(3M)



      _________________________________________________________________
      |________________________________________________________________|
      |		    |		      Types of Errors		       |
      |_____________|__________________________________________________|
      |_____________|_______|______|__________|__________|_______|_____|
      |ESSEL:	    |  -    | -	   |	H     |	  0	 |  -	 | *   |
      |0, y1, yn    |M,	-H  | -	   |	-     |	  -	 |  -	 | -   |
      |(neg. no.)   |	    |	   |	      |		 |	 |     |
      |_____________|_______|______|__________|__________|_______|_____|
      |_____________|_______|______|__________|__________|_______|_____|
      |OW:	    |  -    | -	   |	H     |	  0	 |  -	 | -   |
      |neg.)**(non- |M,	0   | -	   |	-     |	  -	 |  -	 | -   |
      |int.), 0**0  |	    |	   |	      |		 |	 |     |
      |_____________|_______|______|__________|__________|_______|_____|
      |OG:	    |	    |	   |	      |		 |	 |     |
      |og(0):	    |  -    |, -H  |	-     |	  -	 |  -	 | -   |
      |_____________|_______|______|__________|__________|_______|_____|
      |QRT:	    | M, 0  | -	   |	-     |	  -	 |  -	 | -   |
      |_____________|_______|______|__________|__________|_______|_____|
      |_____________|_______|______|__________|__________|_______|_____|
      |YPOT:	    |  -    | -	   |	H     |	  -	 |  -	 | -   |
      |_____________|_______|______|__________|__________|_______|_____|
      |_____________|_______|______|__________|__________|_______|_____|
      |IN, COS:	    |  -    | -	   |	-     |	  -	 | M, 0	 |, *  |
      |_____________|_______|______|__________|__________|_______|_____|
      |_____________|_______|______|__________|__________|_______|_____|
      |COS, ASIN:   | M, 0  | -	   |	-     |	  -	 |  -	 | -   |
      |_____________|_______|______|__________|__________|_______|_____|
	   _____________________________________________________
	   |		       ABBREVIATIONS			|
	   | *	  As much as possible of the value is returned.	|
	   | M	  Message is printed.				|
	   | H	  HUGE is returned.				|
	   | -H	  -HUGE	is returned.				|
	   | 0	  0 is returned.				|
	   |____________________________________________________|



















      Page 3					     (73 A2 02MTA REV1)



