2 /* @(#)s_matherr.c 5.1 93/09/24 */
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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
11 * ====================================================
17 <<matherr>>---modifiable math error handler
24 int matherr(struct exception *<[e]>);
29 struct exception *<[e]>;
32 <<matherr>> is called whenever a math library function generates an error.
33 You can replace <<matherr>> by your own subroutine to customize
34 error treatment. The customized <<matherr>> must return 0 if
35 it fails to resolve the error, and non-zero if the error is resolved.
37 When <<matherr>> returns a nonzero value, no error message is printed
38 and the value of <<errno>> is not modified. You can accomplish either
39 or both of these things in your own <<matherr>> using the information
40 passed in the structure <<*<[e]>>>.
42 This is the <<exception>> structure (defined in `<<math.h>>'):
46 . double arg1, arg2, retval;
50 The members of the exception structure have the following meanings:
53 The type of mathematical error that occured; macros encoding error
54 types are also defined in `<<math.h>>'.
57 a pointer to a null-terminated string holding the
58 name of the math library function where the error occurred.
61 The arguments which caused the error.
64 The error return value (what the calling function will return).
67 If set to be non-zero, this is the new value assigned to <<errno>>.
70 The error types defined in `<<math.h>>' represent possible mathematical
75 An argument was not in the domain of the function; e.g. <<log(-1.0)>>.
78 The requested calculation would result in a singularity; e.g. <<pow(0.0,-2.0)>>
81 A calculation would produce a result too large to represent; e.g.
85 A calculation would produce a result too small to represent; e.g.
89 Total loss of precision. The result would have no significant digits;
93 Partial loss of precision.
98 The library definition for <<matherr>> returns <<0>> in all cases.
100 You can change the calling function's result from a customized <<matherr>>
101 by modifying <<e->retval>>, which propagates backs to the caller.
103 If <<matherr>> returns <<0>> (indicating that it was not able to resolve
104 the error) the caller sets <<errno>> to an appropriate value, and prints
108 <<matherr>> is not ANSI C.
114 int matherr(struct exception
*x
)
121 if(x
->arg1
!=x
->arg1
) return 0;