27 lines
565 B
C
27 lines
565 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <process.h>
|
|
#include <math.h>
|
|
|
|
/* Demonstrate error routine in which negative */
|
|
/* arguments to "sqrt" are treated as positive */
|
|
|
|
static int my_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 );
|
|
}
|
|
|
|
void main( void )
|
|
{
|
|
_set_matherr( &my_matherr );
|
|
printf( "%e\n", sqrt( -5e0 ) );
|
|
exit( 0 );
|
|
}
|