1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Mathematically Undefined Function Policies</title> 5<link rel="stylesheet" href="../../math.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../index.html" title="Math Toolkit 2.12.0"> 8<link rel="up" href="../pol_ref.html" title="Policy Reference"> 9<link rel="prev" href="internal_promotion.html" title="Internal Floating-point Promotion Policies"> 10<link rel="next" href="discrete_quant_ref.html" title="Discrete Quantile Policies"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="internal_promotion.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../pol_ref.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="discrete_quant_ref.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="math_toolkit.pol_ref.assert_undefined"></a><a class="link" href="assert_undefined.html" title="Mathematically Undefined Function Policies">Mathematically 28 Undefined Function Policies</a> 29</h3></div></div></div> 30<p> 31 There are some functions that are generic (they are present for all the statistical 32 distributions supported) but which may be mathematically undefined for certain 33 distributions, but defined for others. 34 </p> 35<p> 36 For example, the Cauchy distribution does not have a meaningful mean, so 37 what should 38 </p> 39<pre class="programlisting"><span class="identifier">mean</span><span class="special">(</span><span class="identifier">cauchy</span><span class="special"><>());</span> 40</pre> 41<p> 42 return, and should such an expression even compile at all? 43 </p> 44<p> 45 The default behaviour is for all such functions to not compile at all - in 46 fact they will raise a <a href="http://www.boost.org/libs/static_assert/index.html" target="_top">static 47 assertion</a> - but by changing the policy we can have them return the 48 result of a domain error instead (which may well throw an exception, depending 49 on the error handling policy). 50 </p> 51<p> 52 This behaviour is controlled by the <code class="computeroutput"><span class="identifier">assert_undefined</span><span class="special"><></span></code> policy: 53 </p> 54<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">policies</span> <span class="special">{</span> 55 56<span class="keyword">template</span> <span class="special"><</span><span class="keyword">bool</span> <span class="identifier">b</span><span class="special">></span> 57<span class="keyword">class</span> <span class="identifier">assert_undefined</span><span class="special">;</span> 58 59<span class="special">}}}</span> <span class="comment">//namespaces</span> 60</pre> 61<p> 62 For example: 63 </p> 64<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">cauchy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 65 66<span class="keyword">using</span> <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> 67<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">;</span> 68 69<span class="comment">// This will not compile, cauchy has no mean!</span> 70<span class="keyword">double</span> <span class="identifier">m1</span> <span class="special">=</span> <span class="identifier">mean</span><span class="special">(</span><span class="identifier">cauchy</span><span class="special">());</span> 71 72<span class="comment">// This will compile, but raises a domain error!</span> 73<span class="keyword">double</span> <span class="identifier">m2</span> <span class="special">=</span> <span class="identifier">mean</span><span class="special">(</span><span class="identifier">cauchy_distribution</span><span class="special"><</span><span class="keyword">double</span><span class="special">,</span> <span class="identifier">policy</span><span class="special"><</span><span class="identifier">assert_undefined</span><span class="special"><</span><span class="keyword">false</span><span class="special">></span> <span class="special">></span> <span class="special">>());</span> 74</pre> 75<p> 76 <code class="computeroutput"><span class="identifier">policy</span><span class="special"><</span><span class="identifier">assert_undefined</span><span class="special"><</span><span class="keyword">false</span><span class="special">></span></code> 77 behaviour can also be obtained by defining the macro 78 </p> 79<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_MATH_ASSERT_UNDEFINED_POLICY</span> <span class="keyword">false</span> 80</pre> 81<p> 82 at the head of the file - see <a class="link" href="policy_defaults.html" title="Using Macros to Change the Policy Defaults">Using 83 Macros to Change the Policy Defaults</a>. 84 </p> 85</div> 86<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 87<td align="left"></td> 88<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar 89 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, 90 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan 91 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, 92 Daryle Walker and Xiaogang Zhang<p> 93 Distributed under the Boost Software License, Version 1.0. (See accompanying 94 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>) 95 </p> 96</div></td> 97</tr></table> 98<hr> 99<div class="spirit-nav"> 100<a accesskey="p" href="internal_promotion.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../pol_ref.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="discrete_quant_ref.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 101</div> 102</body> 103</html> 104