]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/policy_ref_snip12.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / example / policy_ref_snip12.cpp
1 // Copyright John Maddock 2007.
2 // Copyright Paul A. Bristow 2010
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 // Note that this file contains quickbook mark-up as well as code
8 // and comments, don't change any of the special comment mark-ups!
9
10 // Define tgamma function with a no overflow policy
11 // into a specific namespace-scope.
12
13 #include <iostream>
14 using std::cout; using std::endl;
15
16 //[policy_ref_snip12
17
18 #include <boost/math/special_functions/gamma.hpp>
19 //using boost::math::tgamma;
20 // Need not declare using boost::math::tgamma here,
21 // because will define tgamma in myspace using macro below.
22
23 namespace myspace
24 {
25 using namespace boost::math::policies;
26
27 // Define a policy that does not throw on overflow:
28 typedef policy<overflow_error<errno_on_error> > my_policy;
29
30 // Define the special functions in this scope to use the policy:
31 BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS(my_policy)
32 }
33
34 // Now we can use myspace::tgamma etc.
35 // They will automatically use "my_policy":
36 //
37 double t = myspace::tgamma(30.0); // Will *not* throw on overflow,
38 // despite the large value of factorial 30 = 265252859812191058636308480000000
39 // unlike default policy boost::math::tgamma;
40
41 //]
42
43 int main()
44 {
45 cout << "myspace::tgamma(30.0) = " << t << endl;
46 }
47
48 /*
49
50 Output:
51
52 myspace::tgamma(30.0) = 8.84176e+030
53
54 */
55