*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->IRIX man pages -> standard/matherr (3)              
Title
Content
Arch
Section
 

Contents


MATHERR(3M)							   MATHERR(3M)


NAME    [Toc]    [Back]

     matherr - error-handling function

SYNOPSIS    [Toc]    [Back]

     #include <math.h>

     int matherr (struct exception *x);

DESCRIPTION    [Toc]    [Back]

     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    [Toc]    [Back]

     /*
     **	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    [Toc]    [Back]

     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.


									PPPPaaaaggggeeee 6666
[ Back ]
 Similar pages
Name OS Title
cplxerr IRIX error-handling function for the C++ Complex Math Library
iflError IRIX error handling
elf_error IRIX error handling
TIFFError IRIX library error handling interface
clSetErrorHandler IRIX Select an alternate error handling routine
alSetErrorHandler IRIX establish an alternate audio error handling routine
IPC::Open3 IRIX open a process for reading, writing, and error handling
ALseterrorhandler IRIX (obsolete) establish an alternate audio error handling routine
erf Linux error function and complementary error function
erf IRIX error function and complementary error function
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service