[444] | 1 | |
---|
| 2 | /* @(#)s_matherr.c 5.1 93/09/24 */ |
---|
| 3 | /* |
---|
| 4 | * ==================================================== |
---|
| 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
---|
| 6 | * |
---|
| 7 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
---|
| 8 | * Permission to use, copy, modify, and distribute this |
---|
| 9 | * software is freely granted, provided that this notice |
---|
| 10 | * is preserved. |
---|
| 11 | * ==================================================== |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | /* |
---|
| 15 | |
---|
| 16 | FUNCTION |
---|
| 17 | <<matherr>>---modifiable math error handler |
---|
| 18 | |
---|
| 19 | INDEX |
---|
| 20 | matherr |
---|
| 21 | |
---|
| 22 | SYNOPSIS |
---|
| 23 | #include <math.h> |
---|
| 24 | int matherr(struct exception *<[e]>); |
---|
| 25 | |
---|
| 26 | DESCRIPTION |
---|
| 27 | <<matherr>> is called whenever a math library function generates an error. |
---|
| 28 | You can replace <<matherr>> by your own subroutine to customize |
---|
| 29 | error treatment. The customized <<matherr>> must return 0 if |
---|
| 30 | it fails to resolve the error, and non-zero if the error is resolved. |
---|
| 31 | |
---|
| 32 | When <<matherr>> returns a nonzero value, no error message is printed |
---|
| 33 | and the value of <<errno>> is not modified. You can accomplish either |
---|
| 34 | or both of these things in your own <<matherr>> using the information |
---|
| 35 | passed in the structure <<*<[e]>>>. |
---|
| 36 | |
---|
| 37 | This is the <<exception>> structure (defined in `<<math.h>>'): |
---|
| 38 | . struct exception { |
---|
| 39 | . int type; |
---|
| 40 | . char *name; |
---|
| 41 | . double arg1, arg2, retval; |
---|
| 42 | . int err; |
---|
| 43 | . }; |
---|
| 44 | |
---|
| 45 | The members of the exception structure have the following meanings: |
---|
| 46 | o+ |
---|
| 47 | o type |
---|
| 48 | The type of mathematical error that occured; macros encoding error |
---|
| 49 | types are also defined in `<<math.h>>'. |
---|
| 50 | |
---|
| 51 | o name |
---|
| 52 | a pointer to a null-terminated string holding the |
---|
| 53 | name of the math library function where the error occurred. |
---|
| 54 | |
---|
| 55 | o arg1, arg2 |
---|
| 56 | The arguments which caused the error. |
---|
| 57 | |
---|
| 58 | o retval |
---|
| 59 | The error return value (what the calling function will return). |
---|
| 60 | |
---|
| 61 | o err |
---|
| 62 | If set to be non-zero, this is the new value assigned to <<errno>>. |
---|
| 63 | o- |
---|
| 64 | |
---|
| 65 | The error types defined in `<<math.h>>' represent possible mathematical |
---|
| 66 | errors as follows: |
---|
| 67 | |
---|
| 68 | o+ |
---|
| 69 | o DOMAIN |
---|
| 70 | An argument was not in the domain of the function; e.g. <<log(-1.0)>>. |
---|
| 71 | |
---|
| 72 | o SING |
---|
| 73 | The requested calculation would result in a singularity; e.g. <<pow(0.0,-2.0)>> |
---|
| 74 | |
---|
| 75 | o OVERFLOW |
---|
| 76 | A calculation would produce a result too large to represent; e.g. |
---|
| 77 | <<exp(1000.0)>>. |
---|
| 78 | |
---|
| 79 | o UNDERFLOW |
---|
| 80 | A calculation would produce a result too small to represent; e.g. |
---|
| 81 | <<exp(-1000.0)>>. |
---|
| 82 | |
---|
| 83 | o TLOSS |
---|
| 84 | Total loss of precision. The result would have no significant digits; |
---|
| 85 | e.g. <<sin(10e70)>>. |
---|
| 86 | |
---|
| 87 | o PLOSS |
---|
| 88 | Partial loss of precision. |
---|
| 89 | o- |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | RETURNS |
---|
| 93 | The library definition for <<matherr>> returns <<0>> in all cases. |
---|
| 94 | |
---|
| 95 | You can change the calling function's result from a customized <<matherr>> |
---|
| 96 | by modifying <<e->retval>>, which propagates backs to the caller. |
---|
| 97 | |
---|
| 98 | If <<matherr>> returns <<0>> (indicating that it was not able to resolve |
---|
| 99 | the error) the caller sets <<errno>> to an appropriate value, and prints |
---|
| 100 | an error message. |
---|
| 101 | |
---|
| 102 | PORTABILITY |
---|
| 103 | <<matherr>> is not ANSI C. |
---|
| 104 | */ |
---|
| 105 | |
---|
| 106 | #include "fdlibm.h" |
---|
| 107 | |
---|
| 108 | #ifdef __STDC__ |
---|
| 109 | int matherr(struct exception *x) |
---|
| 110 | #else |
---|
| 111 | int matherr(x) |
---|
| 112 | struct exception *x; |
---|
| 113 | #endif |
---|
| 114 | { |
---|
| 115 | int n=0; |
---|
| 116 | if(x->arg1!=x->arg1) return 0; |
---|
| 117 | return n; |
---|
| 118 | } |
---|