Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <math.h>
    int matherr( struct exception *err_info );

Description:
    The matherr function is invoked each time an error is detected by
    functions in the math library.  The default matherr function supplied in
    the library returns zero which causes an error message to be displayed
    upon  stderr and  errno to be set with an appropriate error value.  An
    alternative version of this function can be provided, instead of the
    library version, in order that the error handling for mathematical
    errors can be handled by an application.

    A program may contain a user-written version of matherr to take any
    appropriate action when an error is detected.  When zero is returned, an
    error message will be printed upon  stderr and  errno will be set as was
    the case with the default function.  When a non-zero value is returned,
    no message is printed and  errno is not changed.  The value
    err_info->retval is used as the return value for the function in which
    the error was detected.

    The matherr function is passed a pointer to a structure of type struct
    exception which contains information about the error that has been
    detected:


         struct exception
         { int type;      /* TYPE OF ERROR                */
           char *name;    /* NAME OF FUNCTION             */
           double arg1;   /* FIRST ARGUMENT TO FUNCTION   */
           double arg2;   /* SECOND ARGUMENT TO FUNCTION  */
           double retval; /* DEFAULT RETURN VALUE         */
         };

    The type field will contain one of the following values:

    DOMAIN
        A domain error has occurred, such as sqrt(-1e0).

    SING
        A singularity will result, such as pow(0e0,-2).

    OVERFLOW
        An overflow will result, such as pow(10e0,100).

    UNDERFLOW
        An underflow will result, such as pow(10e0,-100).

    TLOSS
        Total loss of significance will result, such as exp(1000).

    PLOSS
        Partial loss of significance will result, such as sin(10e70).

    The name field points to a string containing the name of the function
    which detected the error.  The fields arg1 and arg2 (if required) give
    the values which caused the error.  The field retval contains the value
    which will be returned by the function.  This value may be changed by a
    user-supplied version of the matherr function.

Returns:
    The matherr function returns zero when an error message is to be printed
    and a non-zero value otherwise.

Example:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>

    /* Demonstrate error routine in which negative */
    /* arguments to "sqrt" are treated as positive */

    void main()
      {
        printf( "%e\n", sqrt( -5e0 ) );
        exit( 0 );
      }

    int matherr( struct exception *err )
      {
        if( strcmp( err->name, "sqrt" ) == 0 ) {
          if( err->type == DOMAIN ) {
            err->retval = sqrt( -(err->arg1) );
            return( 1 );
          } else
            return( 0 );
        } else
          return( 0 );
      }

Classification:
    WATCOM

Systems:
    All

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson