1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117 |
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
- <title>Error Handling</title>
- <link rel="stylesheet" href="../math.css" type="text/css">
- <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
- <link rel="home" href="../index.html" title="Math Toolkit 2.11.0">
- <link rel="up" href="../overview.html" title="Chapter 1. Overview">
- <link rel="prev" href="result_type.html" title="Calculation of the Type of the Result">
- <link rel="next" href="compilers_overview.html" title="Compilers">
- </head>
- <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
- <table cellpadding="2" width="100%"><tr>
- <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
- <td align="center"><a href="../../../../../index.html">Home</a></td>
- <td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
- <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
- <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
- <td align="center"><a href="../../../../../more/index.htm">More</a></td>
- </tr></table>
- <hr>
- <div class="spirit-nav">
- <a accesskey="p" href="result_type.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../overview.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="compilers_overview.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
- </div>
- <div class="section">
- <div class="titlepage"><div><div><h2 class="title" style="clear: both">
- <a name="math_toolkit.error_handling"></a><a class="link" href="error_handling.html" title="Error Handling">Error Handling</a>
- </h2></div></div></div>
- <h4>
- <a name="math_toolkit.error_handling.h0"></a>
- <span class="phrase"><a name="math_toolkit.error_handling.quick_reference"></a></span><a class="link" href="error_handling.html#math_toolkit.error_handling.quick_reference">Quick
- Reference</a>
- </h4>
- <p>
- Handling of errors by this library is split into two orthogonal parts:
- </p>
- <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
- <li class="listitem">
- What kind of error has been raised?
- </li>
- <li class="listitem">
- What should be done when the error is raised?
- </li>
- </ul></div>
- <div class="warning"><table border="0" summary="Warning">
- <tr>
- <td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../doc/src/images/warning.png"></td>
- <th align="left">Warning</th>
- </tr>
- <tr><td align="left" valign="top"><p>
- The default error actions are to throw an exception with an informative error
- message. <span class="red">If you do not try to catch the exception, you
- will not see the message!</span>
- </p></td></tr>
- </table></div>
- <p>
- The kinds of errors that can be raised are:
- </p>
- <div class="variablelist">
- <p class="title"><b></b></p>
- <dl class="variablelist">
- <dt><span class="term">Domain Error</span></dt>
- <dd><p>
- Occurs when one or more arguments to a function are out of range.
- </p></dd>
- <dt><span class="term">Pole Error</span></dt>
- <dd><p>
- Occurs when the particular arguments cause the function to be evaluated
- at a pole with no well defined residual value. For example if <a class="link" href="sf_gamma/tgamma.html" title="Gamma">tgamma</a>
- is evaluated at exactly -2, the function approaches different limiting
- values depending upon whether you approach from just above or just below
- -2. Hence the function has no well defined value at this point and a
- Pole Error will be raised.
- </p></dd>
- <dt><span class="term">Overflow Error</span></dt>
- <dd><p>
- Occurs when the result is either infinite, or too large to represent
- in the numeric type being returned by the function.
- </p></dd>
- <dt><span class="term">Underflow Error</span></dt>
- <dd><p>
- Occurs when the result is not zero, but is too small to be represented
- by any other value in the type being returned by the function.
- </p></dd>
- <dt><span class="term">Denormalisation Error</span></dt>
- <dd><p>
- Occurs when the returned result would be a denormalised value.
- </p></dd>
- <dt><span class="term">Rounding Error</span></dt>
- <dd><p>
- Occurs when the argument to one of the rounding functions <a class="link" href="rounding/trunc.html" title="Truncation Functions">trunc</a>,
- <a class="link" href="rounding/round.html" title="Rounding Functions">round</a> and <a class="link" href="rounding/modf.html" title="Integer and Fractional Part Splitting (modf)">modf</a>
- can not be represented as an integer type, is outside the range of the
- result type.
- </p></dd>
- <dt><span class="term">Evaluation Error</span></dt>
- <dd><p>
- Occurs if no method of evaluation is known, or when an internal error
- occurred that prevented the result from being evaluated: this should
- never occur, but if it does, then it's likely to be due to an iterative
- method not converging fast enough.
- </p></dd>
- <dt><span class="term">Indeterminate Result Error</span></dt>
- <dd><p>
- Occurs when the result of a function is not defined for the values that
- were passed to it.
- </p></dd>
- </dl>
- </div>
- <p>
- The action undertaken by each error condition is determined by the current
- <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> in effect. This can be changed program-wide
- by setting some configuration macros, or at namespace scope, or at the call
- site (by specifying a specific policy in the function call).
- </p>
- <p>
- The available actions are:
- </p>
- <div class="variablelist">
- <p class="title"><b></b></p>
- <dl class="variablelist">
- <dt><span class="term">throw_on_error</span></dt>
- <dd><p>
- Throws the exception most appropriate to the error condition.
- </p></dd>
- <dt><span class="term">errno_on_error</span></dt>
- <dd><p>
- Sets ::errno to an appropriate value, and then returns the most appropriate
- result
- </p></dd>
- <dt><span class="term">ignore_error</span></dt>
- <dd><p>
- Ignores the error and simply the returns the most appropriate result.
- </p></dd>
- <dt><span class="term">user_error</span></dt>
- <dd><p>
- Calls a <a class="link" href="pol_tutorial/user_def_err_pol.html" title="Calling User Defined Error Handlers">user-supplied
- error handler</a>.
- </p></dd>
- </dl>
- </div>
- <p>
- The following tables show all the permutations of errors and actions, with
- the <span class="bold"><strong>default action for each error shown in bold</strong></span>:
- </p>
- <div class="table">
- <a name="math_toolkit.error_handling.possible_actions_for_domain_erro"></a><p class="title"><b>Table 1.1. Possible Actions for Domain Errors</b></p>
- <div class="table-contents"><table class="table" summary="Possible Actions for Domain Errors">
- <colgroup>
- <col>
- <col>
- </colgroup>
- <thead><tr>
- <th>
- <p>
- Action
- </p>
- </th>
- <th>
- <p>
- Behaviour
- </p>
- </th>
- </tr></thead>
- <tbody>
- <tr>
- <td>
- <p>
- throw_on_error
- </p>
- </td>
- <td>
- <p>
- <span class="bold"><strong>Throws <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">domain_error</span></code></strong></span>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- errno_on_error
- </p>
- </td>
- <td>
- <p>
- Sets <code class="computeroutput"><span class="special">::</span><span class="identifier">errno</span></code>
- to <code class="computeroutput"><span class="identifier">EDOM</span></code> and returns
- <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">quiet_NaN</span><span class="special">()</span></code>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- ignore_error
- </p>
- </td>
- <td>
- <p>
- Returns <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">quiet_NaN</span><span class="special">()</span></code>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- user_error
- </p>
- </td>
- <td>
- <p>
- Returns the result of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">user_domain_error</span></code>:
- <a class="link" href="pol_tutorial/user_def_err_pol.html" title="Calling User Defined Error Handlers">this function
- must be defined by the user</a>.
- </p>
- </td>
- </tr>
- </tbody>
- </table></div>
- </div>
- <br class="table-break"><div class="table">
- <a name="math_toolkit.error_handling.possible_actions_for_pole_errors"></a><p class="title"><b>Table 1.2. Possible Actions for Pole Errors</b></p>
- <div class="table-contents"><table class="table" summary="Possible Actions for Pole Errors">
- <colgroup>
- <col>
- <col>
- </colgroup>
- <thead><tr>
- <th>
- <p>
- Action
- </p>
- </th>
- <th>
- <p>
- Behaviour
- </p>
- </th>
- </tr></thead>
- <tbody>
- <tr>
- <td>
- <p>
- throw_on_error
- </p>
- </td>
- <td>
- <p>
- <span class="bold"><strong>Throws <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">domain_error</span></code></strong></span>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- errno_on_error
- </p>
- </td>
- <td>
- <p>
- Sets <code class="computeroutput"><span class="special">::</span><span class="identifier">errno</span></code>
- to <code class="computeroutput"><span class="identifier">EDOM</span></code> and returns
- <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">quiet_NaN</span><span class="special">()</span></code>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- ignore_error
- </p>
- </td>
- <td>
- <p>
- Returns <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">quiet_NaN</span><span class="special">()</span></code>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- user_error
- </p>
- </td>
- <td>
- <p>
- Returns the result of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">user_pole_error</span></code>:
- <a class="link" href="pol_tutorial/user_def_err_pol.html" title="Calling User Defined Error Handlers">this function
- must be defined by the user</a>.
- </p>
- </td>
- </tr>
- </tbody>
- </table></div>
- </div>
- <br class="table-break"><div class="table">
- <a name="math_toolkit.error_handling.possible_actions_for_overflow_er"></a><p class="title"><b>Table 1.3. Possible Actions for Overflow Errors</b></p>
- <div class="table-contents"><table class="table" summary="Possible Actions for Overflow Errors">
- <colgroup>
- <col>
- <col>
- </colgroup>
- <thead><tr>
- <th>
- <p>
- Action
- </p>
- </th>
- <th>
- <p>
- Behaviour
- </p>
- </th>
- </tr></thead>
- <tbody>
- <tr>
- <td>
- <p>
- throw_on_error
- </p>
- </td>
- <td>
- <p>
- <span class="bold"><strong>Throws <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code></strong></span>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- errno_on_error
- </p>
- </td>
- <td>
- <p>
- Sets <code class="computeroutput"><span class="special">::</span><span class="identifier">errno</span></code>
- to <code class="computeroutput"><span class="identifier">ERANGE</span></code> and returns
- <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">infinity</span><span class="special">()</span></code>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- ignore_error
- </p>
- </td>
- <td>
- <p>
- Returns <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">infinity</span><span class="special">()</span></code>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- user_error
- </p>
- </td>
- <td>
- <p>
- Returns the result of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">user_overflow_error</span></code>:
- <a class="link" href="pol_tutorial/user_def_err_pol.html" title="Calling User Defined Error Handlers">this function
- must be defined by the user</a>.
- </p>
- </td>
- </tr>
- </tbody>
- </table></div>
- </div>
- <br class="table-break"><div class="table">
- <a name="math_toolkit.error_handling.possible_actions_for_underflow_e"></a><p class="title"><b>Table 1.4. Possible Actions for Underflow Errors</b></p>
- <div class="table-contents"><table class="table" summary="Possible Actions for Underflow Errors">
- <colgroup>
- <col>
- <col>
- </colgroup>
- <thead><tr>
- <th>
- <p>
- Action
- </p>
- </th>
- <th>
- <p>
- Behaviour
- </p>
- </th>
- </tr></thead>
- <tbody>
- <tr>
- <td>
- <p>
- throw_on_error
- </p>
- </td>
- <td>
- <p>
- Throws <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">underflow_error</span></code>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- errno_on_error
- </p>
- </td>
- <td>
- <p>
- Sets <code class="computeroutput"><span class="special">::</span><span class="identifier">errno</span></code>
- to <code class="computeroutput"><span class="identifier">ERANGE</span></code> and returns
- 0.
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- ignore_error
- </p>
- </td>
- <td>
- <p>
- <span class="bold"><strong>Returns 0</strong></span>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- user_error
- </p>
- </td>
- <td>
- <p>
- Returns the result of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">user_underflow_error</span></code>:
- <a class="link" href="pol_tutorial/user_def_err_pol.html" title="Calling User Defined Error Handlers">this function
- must be defined by the user</a>.
- </p>
- </td>
- </tr>
- </tbody>
- </table></div>
- </div>
- <br class="table-break"><div class="table">
- <a name="math_toolkit.error_handling.possible_actions_for_denorm_erro"></a><p class="title"><b>Table 1.5. Possible Actions for Denorm Errors</b></p>
- <div class="table-contents"><table class="table" summary="Possible Actions for Denorm Errors">
- <colgroup>
- <col>
- <col>
- </colgroup>
- <thead><tr>
- <th>
- <p>
- Action
- </p>
- </th>
- <th>
- <p>
- Behaviour
- </p>
- </th>
- </tr></thead>
- <tbody>
- <tr>
- <td>
- <p>
- throw_on_error
- </p>
- </td>
- <td>
- <p>
- Throws <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">underflow_error</span></code>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- errno_on_error
- </p>
- </td>
- <td>
- <p>
- Sets <code class="computeroutput"><span class="special">::</span><span class="identifier">errno</span></code>
- to <code class="computeroutput"><span class="identifier">ERANGE</span></code> and returns
- the denormalised value.
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- ignore_error
- </p>
- </td>
- <td>
- <p>
- <span class="bold"><strong>Returns the denormalised value.</strong></span>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- user_error
- </p>
- </td>
- <td>
- <p>
- Returns the result of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">user_denorm_error</span></code>:
- <a class="link" href="pol_tutorial/user_def_err_pol.html" title="Calling User Defined Error Handlers">this function
- must be defined by the user</a>.
- </p>
- </td>
- </tr>
- </tbody>
- </table></div>
- </div>
- <br class="table-break"><div class="table">
- <a name="math_toolkit.error_handling.possible_actions_for_rounding_er"></a><p class="title"><b>Table 1.6. Possible Actions for Rounding Errors</b></p>
- <div class="table-contents"><table class="table" summary="Possible Actions for Rounding Errors">
- <colgroup>
- <col>
- <col>
- </colgroup>
- <thead><tr>
- <th>
- <p>
- Action
- </p>
- </th>
- <th>
- <p>
- Behaviour
- </p>
- </th>
- </tr></thead>
- <tbody>
- <tr>
- <td>
- <p>
- throw_on_error
- </p>
- </td>
- <td>
- <p>
- Throws <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">rounding_error</span></code>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- errno_on_error
- </p>
- </td>
- <td>
- <p>
- Sets <code class="computeroutput"><span class="special">::</span><span class="identifier">errno</span></code>
- to <code class="computeroutput"><span class="identifier">ERANGE</span></code> and returns
- the largest representable value of the target integer type (or the
- most negative value if the argument to the function was less than
- zero).
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- ignore_error
- </p>
- </td>
- <td>
- <p>
- <span class="bold"><strong>Returns the largest representable value of
- the target integer type (or the most negative value if the argument
- to the function was less than zero).</strong></span>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- user_error
- </p>
- </td>
- <td>
- <p>
- Returns the result of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">user_rounding_error</span></code>:
- <a class="link" href="pol_tutorial/user_def_err_pol.html" title="Calling User Defined Error Handlers">this function
- must be defined by the user</a>.
- </p>
- </td>
- </tr>
- </tbody>
- </table></div>
- </div>
- <br class="table-break"><div class="table">
- <a name="math_toolkit.error_handling.possible_actions_for_internal_ev"></a><p class="title"><b>Table 1.7. Possible Actions for Internal Evaluation Errors</b></p>
- <div class="table-contents"><table class="table" summary="Possible Actions for Internal Evaluation Errors">
- <colgroup>
- <col>
- <col>
- </colgroup>
- <thead><tr>
- <th>
- <p>
- Action
- </p>
- </th>
- <th>
- <p>
- Behaviour
- </p>
- </th>
- </tr></thead>
- <tbody>
- <tr>
- <td>
- <p>
- throw_on_error
- </p>
- </td>
- <td>
- <p>
- <span class="bold"><strong>Throws <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">evaluation_error</span></code></strong></span>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- errno_on_error
- </p>
- </td>
- <td>
- <p>
- Sets <code class="computeroutput"><span class="special">::</span><span class="identifier">errno</span></code>
- to <code class="computeroutput"><span class="identifier">EDOM</span></code> and returns
- the closest approximation found.
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- ignore_error
- </p>
- </td>
- <td>
- <p>
- Returns the closest approximation found.
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- user_error
- </p>
- </td>
- <td>
- <p>
- Returns the result of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">user_evaluation_error</span></code>:
- <a class="link" href="pol_tutorial/user_def_err_pol.html" title="Calling User Defined Error Handlers">this function
- must be defined by the user</a>.
- </p>
- </td>
- </tr>
- </tbody>
- </table></div>
- </div>
- <br class="table-break"><div class="table">
- <a name="math_toolkit.error_handling.possible_actions_for_indetermina"></a><p class="title"><b>Table 1.8. Possible Actions for Indeterminate Result Errors</b></p>
- <div class="table-contents"><table class="table" summary="Possible Actions for Indeterminate Result Errors">
- <colgroup>
- <col>
- <col>
- </colgroup>
- <thead><tr>
- <th>
- <p>
- Action
- </p>
- </th>
- <th>
- <p>
- Behaviour
- </p>
- </th>
- </tr></thead>
- <tbody>
- <tr>
- <td>
- <p>
- throw_on_error
- </p>
- </td>
- <td>
- <p>
- Throws <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">domain_error</span></code>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- errno_on_error
- </p>
- </td>
- <td>
- <p>
- Sets <code class="computeroutput"><span class="special">::</span><span class="identifier">errno</span></code>
- to <code class="computeroutput"><span class="identifier">EDOM</span></code> and returns
- the same value as <code class="computeroutput"><span class="identifier">ignore_error</span></code>.
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- ignore_error
- </p>
- </td>
- <td>
- <p>
- <span class="bold"><strong>Returns a default result that depends on the
- function where the error occurred.</strong></span>
- </p>
- </td>
- </tr>
- <tr>
- <td>
- <p>
- user_error
- </p>
- </td>
- <td>
- <p>
- Returns the result of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">user_indeterminate_result_error</span></code>:
- <a class="link" href="pol_tutorial/user_def_err_pol.html" title="Calling User Defined Error Handlers">this function
- must be defined by the user</a>.
- </p>
- </td>
- </tr>
- </tbody>
- </table></div>
- </div>
- <br class="table-break"><p>
- All these error conditions are in namespace boost::math::policies, made available,
- for example, a by namespace declaration using <code class="computeroutput"><span class="keyword">namespace</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">;</span></code> or individual using declarations <code class="computeroutput"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">overflow_error</span><span class="special">;</span></code>.
- </p>
- <h4>
- <a name="math_toolkit.error_handling.h1"></a>
- <span class="phrase"><a name="math_toolkit.error_handling.rationale"></a></span><a class="link" href="error_handling.html#math_toolkit.error_handling.rationale">Rationale</a>
- </h4>
- <p>
- The flexibility of the current implementation should be reasonably obvious:
- the default behaviours were chosen based on feedback during the formal review
- of this library. It was felt that:
- </p>
- <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
- <li class="listitem">
- Genuine errors should be flagged with exceptions rather than following
- C-compatible behaviour and setting <code class="computeroutput"><span class="special">::</span><span class="identifier">errno</span></code>.
- </li>
- <li class="listitem">
- Numeric underflow and denormalised results were not considered to be fatal
- errors in most cases, so it was felt that these should be ignored.
- </li>
- <li class="listitem">
- If there is more than one error, only the first detected will be reported
- in the throw message.
- </li>
- </ul></div>
- <h4>
- <a name="math_toolkit.error_handling.h2"></a>
- <span class="phrase"><a name="math_toolkit.error_handling.finding_more_information"></a></span><a class="link" href="error_handling.html#math_toolkit.error_handling.finding_more_information">Finding
- More Information</a>
- </h4>
- <p>
- There are some pre-processor macro defines that can be used to <a class="link" href="pol_ref/policy_defaults.html" title="Using Macros to Change the Policy Defaults">change
- the policy defaults</a>. See also the <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">policy section</a>.
- </p>
- <p>
- An example is at the Policy tutorial in <a class="link" href="pol_tutorial/changing_policy_defaults.html" title="Changing the Policy Defaults">Changing
- the Policy Defaults</a>.
- </p>
- <p>
- Full source code of this typical example of passing a 'bad' argument (negative
- degrees of freedom) to Student's t distribution is <a class="link" href="stat_tut/weg/error_eg.html" title="Error Handling Example">in
- the error handling example</a>.
- </p>
- <p>
- The various kind of errors are described in more detail below.
- </p>
- <h4>
- <a name="math_toolkit.error_handling.h3"></a>
- <span class="phrase"><a name="math_toolkit.error_handling.domain_error"></a></span><a class="link" href="error_handling.html#math_toolkit.error_handling.domain_error">Domain
- Errors</a>
- </h4>
- <p>
- When a special function is passed an argument that is outside the range of
- values for which that function is defined, then the function returns the result
- of:
- </p>
- <pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">raise_domain_error</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">FunctionName</span><span class="special">,</span> <span class="identifier">Message</span><span class="special">,</span> <span class="identifier">Val</span><span class="special">,</span> <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">);</span>
- </pre>
- <p>
- Where <code class="computeroutput"><span class="identifier">T</span></code> is the floating-point
- type passed to the function, <code class="computeroutput"><span class="identifier">FunctionName</span></code>
- is the name of the function, <code class="computeroutput"><span class="identifier">Message</span></code>
- is an error message describing the problem, Val is the value that was out of
- range, and <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> is the current policy in use
- for the function that was called.
- </p>
- <p>
- The default policy behaviour of this function is to throw a std::domain_error
- C++ exception. But if the <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> is to ignore
- the error, or set global <code class="computeroutput"><span class="special">::</span><span class="identifier">errno</span></code>,
- then a NaN will be returned.
- </p>
- <p>
- This behaviour is chosen to assist compatibility with the behaviour of <span class="emphasis"><em>ISO/IEC
- 9899:1999 Programming languages - C</em></span> and with the <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf" target="_top">Draft
- Technical Report on C++ Library Extensions, 2005-06-24, section 5.2.1, paragraph
- 6</a>:
- </p>
- <div class="blockquote"><blockquote class="blockquote"><p>
- <span class="emphasis"><em>"Each of the functions declared above shall return a NaN (Not
- a Number) if any argument value is a NaN, but it shall not report a domain
- error. Otherwise, each of the functions declared above shall report a domain
- error for just those argument values for which:<br> the function description's
- Returns clause explicitly specifies a domain, and those arguments fall outside
- the specified domain; or <br> the corresponding mathematical function value
- has a non-zero imaginary component; or <br> the corresponding mathematical
- function is not mathematically defined. <br> Note 2: A mathematical function
- is mathematically defined for a given set of argument values if it is explicitly
- defined for that set of argument values or if its limiting value exists and
- does not depend on the direction of approach."</em></span>
- </p></blockquote></div>
- <p>
- Note that in order to support information-rich error messages when throwing
- exceptions, <code class="computeroutput"><span class="identifier">Message</span></code> must contain
- a <a href="../../../../format/index.html" target="_top">Boost.Format</a> recognised format
- specifier: the argument <code class="computeroutput"><span class="identifier">Val</span></code>
- is inserted into the error message according to the specifier used.
- </p>
- <p>
- For example if <code class="computeroutput"><span class="identifier">Message</span></code> contains
- a "%1%" then it is replaced by the value of <code class="computeroutput"><span class="identifier">Val</span></code>
- to the full precision of T, where as "%.3g" would contain the value
- of <code class="computeroutput"><span class="identifier">Val</span></code> to 3 digits. See the
- <a href="../../../../format/index.html" target="_top">Boost.Format</a> documentation
- for more details.
- </p>
- <h4>
- <a name="math_toolkit.error_handling.h4"></a>
- <span class="phrase"><a name="math_toolkit.error_handling.pole_error"></a></span><a class="link" href="error_handling.html#math_toolkit.error_handling.pole_error">Evaluation
- at a pole</a>
- </h4>
- <p>
- When a special function is passed an argument that is at a pole without a well
- defined residual value, then the function returns the result of:
- </p>
- <pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">raise_pole_error</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">FunctionName</span><span class="special">,</span> <span class="identifier">Message</span><span class="special">,</span> <span class="identifier">Val</span><span class="special">,</span> <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">);</span>
- </pre>
- <p>
- Where <code class="computeroutput"><span class="identifier">T</span></code> is the floating point
- type passed to the function, <code class="computeroutput"><span class="identifier">FunctionName</span></code>
- is the name of the function, <code class="computeroutput"><span class="identifier">Message</span></code>
- is an error message describing the problem, <code class="computeroutput"><span class="identifier">Val</span></code>
- is the value of the argument that is at a pole, and <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a>
- is the current policy in use for the function that was called.
- </p>
- <p>
- The default behaviour of this function is to throw a std::domain_error exception.
- But <a class="link" href="pol_ref/error_handling_policies.html" title="Error Handling Policies">error handling
- policies</a> can be used to change this, for example to <code class="computeroutput"><span class="identifier">ignore_error</span></code>
- and return NaN.
- </p>
- <p>
- Note that in order to support information-rich error messages when throwing
- exceptions, <code class="computeroutput"><span class="identifier">Message</span></code> must contain
- a <a href="../../../../format/index.html" target="_top">Boost.Format</a> recognised format
- specifier: the argument <code class="computeroutput"><span class="identifier">val</span></code>
- is inserted into the error message according to the specifier used.
- </p>
- <p>
- For example if <code class="computeroutput"><span class="identifier">Message</span></code> contains
- a "%1%" then it is replaced by the value of <code class="computeroutput"><span class="identifier">val</span></code>
- to the full precision of T, where as "%.3g" would contain the value
- of <code class="computeroutput"><span class="identifier">val</span></code> to 3 digits. See the
- <a href="../../../../format/index.html" target="_top">Boost.Format</a> documentation
- for more details.
- </p>
- <h4>
- <a name="math_toolkit.error_handling.h5"></a>
- <span class="phrase"><a name="math_toolkit.error_handling.overflow_error"></a></span><a class="link" href="error_handling.html#math_toolkit.error_handling.overflow_error">Numeric
- Overflow</a>
- </h4>
- <p>
- When the result of a special function is too large to fit in the argument floating-point
- type, then the function returns the result of:
- </p>
- <pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">raise_overflow_error</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">FunctionName</span><span class="special">,</span> <span class="identifier">Message</span><span class="special">,</span> <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">);</span>
- </pre>
- <p>
- Where <code class="computeroutput"><span class="identifier">T</span></code> is the floating-point
- type passed to the function, <code class="computeroutput"><span class="identifier">FunctionName</span></code>
- is the name of the function, <code class="computeroutput"><span class="identifier">Message</span></code>
- is an error message describing the problem, and <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a>
- is the current policy in use for the function that was called.
- </p>
- <p>
- The default policy for this function is that <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code>
- C++ exception is thrown. But if, for example, an <code class="computeroutput"><span class="identifier">ignore_error</span></code>
- policy is used, then returns <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">infinity</span><span class="special">()</span></code>.
- In this situation if the type <code class="computeroutput"><span class="identifier">T</span></code>
- doesn't support infinities, the maximum value for the type is returned.
- </p>
- <h4>
- <a name="math_toolkit.error_handling.h6"></a>
- <span class="phrase"><a name="math_toolkit.error_handling.underflow_error"></a></span><a class="link" href="error_handling.html#math_toolkit.error_handling.underflow_error">Numeric
- Underflow</a>
- </h4>
- <p>
- If the result of a special function is known to be non-zero, but the calculated
- result underflows to zero, then the function returns the result of:
- </p>
- <pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">raise_underflow_error</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">FunctionName</span><span class="special">,</span> <span class="identifier">Message</span><span class="special">,</span> <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">);</span>
- </pre>
- <p>
- Where <code class="computeroutput"><span class="identifier">T</span></code> is the floating point
- type passed to the function, <code class="computeroutput"><span class="identifier">FunctionName</span></code>
- is the name of the function, <code class="computeroutput"><span class="identifier">Message</span></code>
- is an error message describing the problem, and <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a>
- is the current policy in use for the called function.
- </p>
- <p>
- The default version of this function returns zero. But with another policy,
- like <code class="computeroutput"><span class="identifier">throw_on_error</span></code>, throws
- an <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">underflow_error</span></code> C++ exception.
- </p>
- <h4>
- <a name="math_toolkit.error_handling.h7"></a>
- <span class="phrase"><a name="math_toolkit.error_handling.denorm_error"></a></span><a class="link" href="error_handling.html#math_toolkit.error_handling.denorm_error">Denormalisation
- Errors</a>
- </h4>
- <p>
- If the result of a special function is a denormalised value <span class="emphasis"><em>z</em></span>
- then the function returns the result of:
- </p>
- <pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">raise_denorm_error</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">z</span><span class="special">,</span> <span class="identifier">FunctionName</span><span class="special">,</span> <span class="identifier">Message</span><span class="special">,</span> <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">);</span>
- </pre>
- <p>
- Where <code class="computeroutput"><span class="identifier">T</span></code> is the floating point
- type passed to the function, <code class="computeroutput"><span class="identifier">FunctionName</span></code>
- is the name of the function, <code class="computeroutput"><span class="identifier">Message</span></code>
- is an error message describing the problem, and <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a>
- is the current policy in use for the called function.
- </p>
- <p>
- The default version of this function returns <span class="emphasis"><em>z</em></span>. But with
- another policy, like <code class="computeroutput"><span class="identifier">throw_on_error</span></code>
- throws an <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">underflow_error</span></code> C++ exception.
- </p>
- <h4>
- <a name="math_toolkit.error_handling.h8"></a>
- <span class="phrase"><a name="math_toolkit.error_handling.evaluation_error"></a></span><a class="link" href="error_handling.html#math_toolkit.error_handling.evaluation_error">Evaluation
- Errors</a>
- </h4>
- <p>
- When a special function calculates a result that is known to be erroneous,
- or where the result is incalculable then it calls:
- </p>
- <pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">raise_evaluation_error</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">FunctionName</span><span class="special">,</span> <span class="identifier">Message</span><span class="special">,</span> <span class="identifier">Val</span><span class="special">,</span> <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">);</span>
- </pre>
- <p>
- Where <code class="computeroutput"><span class="identifier">T</span></code> is the floating point
- type passed to the function, <code class="computeroutput"><span class="identifier">FunctionName</span></code>
- is the name of the function, <code class="computeroutput"><span class="identifier">Message</span></code>
- is an error message describing the problem, <code class="computeroutput"><span class="identifier">Val</span></code>
- is the erroneous value, and <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> is the current
- policy in use for the called function.
- </p>
- <p>
- The default behaviour of this function is to throw a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">evaluation_error</span></code>.
- </p>
- <p>
- Note that in order to support information rich error messages when throwing
- exceptions, <code class="computeroutput"><span class="identifier">Message</span></code> must contain
- a <a href="../../../../format/index.html" target="_top">Boost.Format</a> recognised format
- specifier: the argument <code class="computeroutput"><span class="identifier">val</span></code>
- is inserted into the error message according to the specifier used.
- </p>
- <p>
- For example if <code class="computeroutput"><span class="identifier">Message</span></code> contains
- a "%1%" then it is replaced by the value of <code class="computeroutput"><span class="identifier">val</span></code>
- to the full precision of T, where as "%.3g" would contain the value
- of <code class="computeroutput"><span class="identifier">val</span></code> to 3 digits. See the
- <a href="../../../../format/index.html" target="_top">Boost.Format</a> documentation
- for more details.
- </p>
- <h4>
- <a name="math_toolkit.error_handling.h9"></a>
- <span class="phrase"><a name="math_toolkit.error_handling.indeterminate_result_error"></a></span><a class="link" href="error_handling.html#math_toolkit.error_handling.indeterminate_result_error">Indeterminate
- Result Errors</a>
- </h4>
- <p>
- When the result of a special function is indeterminate for the value that was
- passed to it, then the function returns the result of:
- </p>
- <pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">raise_overflow_error</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">FunctionName</span><span class="special">,</span> <span class="identifier">Message</span><span class="special">,</span> <span class="identifier">Val</span><span class="special">,</span> <span class="identifier">Default</span><span class="special">,</span> <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">);</span>
- </pre>
- <p>
- Where <code class="computeroutput"><span class="identifier">T</span></code> is the floating-point
- type passed to the function, <code class="computeroutput"><span class="identifier">FunctionName</span></code>
- is the name of the function, <code class="computeroutput"><span class="identifier">Message</span></code>
- is an error message describing the problem, Val is the value for which the
- result is indeterminate, Default is an alternative default result that must
- be returned for <code class="computeroutput"><span class="identifier">ignore_error</span></code>
- and <code class="computeroutput"><span class="identifier">errno_on_erro</span></code> policies,
- and <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> is the current policy in use for the
- function that was called.
- </p>
- <p>
- The default policy for this function is <code class="computeroutput"><span class="identifier">ignore_error</span></code>:
- note that this error type is reserved for situations where the result is mathematically
- undefined or indeterminate, but there is none the less a convention for what
- the result should be: for example the C99 standard specifies that the result
- of 0<sup>0</sup> is 1, even though the result is actually mathematically indeterminate.
- </p>
- <h4>
- <a name="math_toolkit.error_handling.h10"></a>
- <span class="phrase"><a name="math_toolkit.error_handling.rounding_error"></a></span><a class="link" href="error_handling.html#math_toolkit.error_handling.rounding_error">Rounding
- Errors</a>
- </h4>
- <p>
- When one of the rounding functions <a class="link" href="rounding/round.html" title="Rounding Functions">round</a>,
- <a class="link" href="rounding/trunc.html" title="Truncation Functions">trunc</a> or <a class="link" href="rounding/modf.html" title="Integer and Fractional Part Splitting (modf)">modf</a>
- is called with an argument that has no integer representation, or is too large
- to be represented in the result type then the value returned is the result
- of a call to:
- </p>
- <pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">raise_rounding_error</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">FunctionName</span><span class="special">,</span> <span class="identifier">Message</span><span class="special">,</span> <span class="identifier">Val</span><span class="special">,</span> <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">);</span>
- </pre>
- <p>
- Where <code class="computeroutput"><span class="identifier">T</span></code> is the floating point
- type passed to the function, <code class="computeroutput"><span class="identifier">FunctionName</span></code>
- is the name of the function, <code class="computeroutput"><span class="identifier">Message</span></code>
- is an error message describing the problem, <code class="computeroutput"><span class="identifier">Val</span></code>
- is the erroneous argument, and <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a> is the
- current policy in use for the called function.
- </p>
- <p>
- The default behaviour of this function is to throw a <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">rounding_error</span></code>.
- </p>
- <p>
- Note that in order to support information rich error messages when throwing
- exceptions, <code class="computeroutput"><span class="identifier">Message</span></code> must contain
- a <a href="../../../../format/index.html" target="_top">Boost.Format</a> recognised format
- specifier: the argument <code class="computeroutput"><span class="identifier">val</span></code>
- is inserted into the error message according to the specifier used.
- </p>
- <p>
- For example if <code class="computeroutput"><span class="identifier">Message</span></code> contains
- a "%1%" then it is replaced by the value of <code class="computeroutput"><span class="identifier">val</span></code>
- to the full precision of T, where as "%.3g" would contain the value
- of <code class="computeroutput"><span class="identifier">val</span></code> to 3 digits. See the
- <a href="../../../../format/index.html" target="_top">Boost.Format</a> documentation
- for more details.
- </p>
- <h4>
- <a name="math_toolkit.error_handling.h11"></a>
- <span class="phrase"><a name="math_toolkit.error_handling.checked_narrowing_cast"></a></span><a class="link" href="error_handling.html#math_toolkit.error_handling.checked_narrowing_cast">Errors
- from typecasts</a>
- </h4>
- <p>
- Many special functions evaluate their results at a higher precision than their
- arguments in order to ensure full machine precision in the result: for example,
- a function passed a float argument may evaluate its result using double precision
- internally. Many of the errors listed above may therefore occur not during
- evaluation, but when converting the result to the narrower result type. The
- function:
- </p>
- <pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../policy.html" title="Chapter 20. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
- <span class="identifier">T</span> <span class="identifier">checked_narrowing_cast</span><span class="special">(</span><span class="identifier">U</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">val</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">function</span><span class="special">);</span>
- </pre>
- <p>
- Is used to perform these conversions, and will call the error handlers listed
- above on <a class="link" href="error_handling.html#math_toolkit.error_handling.overflow_error">overflow</a>,
- <a class="link" href="error_handling.html#math_toolkit.error_handling.underflow_error">underflow</a>
- or <a class="link" href="error_handling.html#math_toolkit.error_handling.denorm_error">denormalisation</a>.
- </p>
- </div>
- <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
- <td align="left"></td>
- <td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
- Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
- Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
- Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
- Daryle Walker and Xiaogang Zhang<p>
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
- </p>
- </div></td>
- </tr></table>
- <hr>
- <div class="spirit-nav">
- <a accesskey="p" href="result_type.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../overview.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="compilers_overview.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
- </div>
- </body>
- </html>
|