]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/doc/html/math_toolkit/pol_ref/assert_undefined.html
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / doc / html / math_toolkit / pol_ref / assert_undefined.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
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.77.1">
7 <link rel="home" href="../../index.html" title="Math Toolkit 2.5.1">
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">&lt;&gt;());</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">&lt;&gt;</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">&lt;</span><span class="keyword">bool</span> <span class="identifier">b</span><span class="special">&gt;</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">&lt;</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">&gt;</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">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="identifier">policy</span><span class="special">&lt;</span><span class="identifier">assert_undefined</span><span class="special">&lt;</span><span class="keyword">false</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="special">&gt;());</span>
74 </pre>
75 <p>
76 <code class="computeroutput"><span class="identifier">policy</span><span class="special">&lt;</span><span class="identifier">assert_undefined</span><span class="special">&lt;</span><span class="keyword">false</span><span class="special">&gt;</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 &#169; 2006-2010, 2012-2014 Nikhar Agrawal,
89 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
90 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R&#229;de, Gautam Sewani,
91 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang<p>
92 Distributed under the Boost Software License, Version 1.0. (See accompanying
93 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>)
94 </p>
95 </div></td>
96 </tr></table>
97 <hr>
98 <div class="spirit-nav">
99 <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>
100 </div>
101 </body>
102 </html>