| <html lang="en"> |
| <head> |
| <title>matherr - Untitled</title> |
| <meta http-equiv="Content-Type" content="text/html"> |
| <meta name="description" content="Untitled"> |
| <meta name="generator" content="makeinfo 4.13"> |
| <link title="Top" rel="start" href="index.html#Top"> |
| <link rel="up" href="Math.html#Math" title="Math"> |
| <link rel="prev" href="lround.html#lround" title="lround"> |
| <link rel="next" href="modf.html#modf" title="modf"> |
| <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <style type="text/css"><!-- |
| pre.display { font-family:inherit } |
| pre.format { font-family:inherit } |
| pre.smalldisplay { font-family:inherit; font-size:smaller } |
| pre.smallformat { font-family:inherit; font-size:smaller } |
| pre.smallexample { font-size:smaller } |
| pre.smalllisp { font-size:smaller } |
| span.sc { font-variant:small-caps } |
| span.roman { font-family:serif; font-weight:normal; } |
| span.sansserif { font-family:sans-serif; font-weight:normal; } |
| --></style> |
| </head> |
| <body> |
| <div class="node"> |
| <a name="matherr"></a> |
| <p> |
| Next: <a rel="next" accesskey="n" href="modf.html#modf">modf</a>, |
| Previous: <a rel="previous" accesskey="p" href="lround.html#lround">lround</a>, |
| Up: <a rel="up" accesskey="u" href="Math.html#Math">Math</a> |
| <hr> |
| </div> |
| |
| <h3 class="section">1.40 <code>matherr</code>—modifiable math error handler</h3> |
| |
| <p><a name="index-matherr-116"></a><strong>Synopsis</strong> |
| <pre class="example"> #include <math.h> |
| int matherr(struct exception *<var>e</var>); |
| |
| </pre> |
| <p><strong>Description</strong><br> |
| <code>matherr</code> is called whenever a math library function generates an error. |
| You can replace <code>matherr</code> by your own subroutine to customize |
| error treatment. The customized <code>matherr</code> must return 0 if |
| it fails to resolve the error, and non-zero if the error is resolved. |
| |
| <p>When <code>matherr</code> returns a nonzero value, no error message is printed |
| and the value of <code>errno</code> is not modified. You can accomplish either |
| or both of these things in your own <code>matherr</code> using the information |
| passed in the structure <code>*</code><var>e</var>. |
| |
| <p>This is the <code>exception</code> structure (defined in `<code>math.h</code>'): |
| <pre class="smallexample"> struct exception { |
| int type; |
| char *name; |
| double arg1, arg2, retval; |
| int err; |
| }; |
| </pre> |
| <p>The members of the exception structure have the following meanings: |
| <dl> |
| <dt><code>type</code><dd>The type of mathematical error that occured; macros encoding error |
| types are also defined in `<code>math.h</code>'. |
| |
| <br><dt><code>name</code><dd>a pointer to a null-terminated string holding the |
| name of the math library function where the error occurred. |
| |
| <br><dt><code>arg1, arg2</code><dd>The arguments which caused the error. |
| |
| <br><dt><code>retval</code><dd>The error return value (what the calling function will return). |
| |
| <br><dt><code>err</code><dd>If set to be non-zero, this is the new value assigned to <code>errno</code>. |
| </dl> |
| |
| <p>The error types defined in `<code>math.h</code>' represent possible mathematical |
| errors as follows: |
| |
| <dl> |
| <dt><code>DOMAIN</code><dd>An argument was not in the domain of the function; e.g. <code>log(-1.0)</code>. |
| |
| <br><dt><code>SING</code><dd>The requested calculation would result in a singularity; e.g. <code>pow(0.0,-2.0)</code> |
| |
| <br><dt><code>OVERFLOW</code><dd>A calculation would produce a result too large to represent; e.g. |
| <code>exp(1000.0)</code>. |
| |
| <br><dt><code>UNDERFLOW</code><dd>A calculation would produce a result too small to represent; e.g. |
| <code>exp(-1000.0)</code>. |
| |
| <br><dt><code>TLOSS</code><dd>Total loss of precision. The result would have no significant digits; |
| e.g. <code>sin(10e70)</code>. |
| |
| <br><dt><code>PLOSS</code><dd>Partial loss of precision. |
| </dl> |
| |
| <p><br> |
| <strong>Returns</strong><br> |
| The library definition for <code>matherr</code> returns <code>0</code> in all cases. |
| |
| <p>You can change the calling function's result from a customized <code>matherr</code> |
| by modifying <code>e->retval</code>, which propagates backs to the caller. |
| |
| <p>If <code>matherr</code> returns <code>0</code> (indicating that it was not able to resolve |
| the error) the caller sets <code>errno</code> to an appropriate value, and prints |
| an error message. |
| |
| <p><br> |
| <strong>Portability</strong><br> |
| <code>matherr</code> is not ANSI C. |
| |
| <p><br> |
| |
| </body></html> |
| |