]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/policy_eg_1.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / example / policy_eg_1.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 #include <iostream>
8 using std::cout; using std::endl;
9 #include <cerrno> // for ::errno
10
11 //[policy_eg_1
12
13 #include <boost/math/special_functions/gamma.hpp>
14 using boost::math::tgamma;
15
16 // Define the policy to use:
17 using namespace boost::math::policies; // may be convenient, or
18
19 using boost::math::policies::policy;
20 // Types of error whose action can be altered by policies:.
21 using boost::math::policies::evaluation_error;
22 using boost::math::policies::domain_error;
23 using boost::math::policies::overflow_error;
24 using boost::math::policies::domain_error;
25 using boost::math::policies::pole_error;
26 // Actions on error (in enum error_policy_type):
27 using boost::math::policies::errno_on_error;
28 using boost::math::policies::ignore_error;
29 using boost::math::policies::throw_on_error;
30 using boost::math::policies::user_error;
31
32 typedef policy<
33 domain_error<errno_on_error>,
34 pole_error<errno_on_error>,
35 overflow_error<errno_on_error>,
36 evaluation_error<errno_on_error>
37 > c_policy;
38 //
39 // Now use the policy when calling tgamma:
40
41 // http://msdn.microsoft.com/en-us/library/t3ayayh1.aspx
42 // Microsoft errno declared in STDLIB.H as "extern int errno;"
43
44 int main()
45 {
46 errno = 0; // Reset.
47 cout << "Result of tgamma(30000) is: "
48 << tgamma(30000, c_policy()) << endl; // Too big parameter
49 cout << "errno = " << errno << endl; // errno 34 Numerical result out of range.
50 cout << "Result of tgamma(-10) is: "
51 << boost::math::tgamma(-10, c_policy()) << endl; // Negative parameter.
52 cout << "errno = " << errno << endl; // error 33 Numerical argument out of domain.
53 } // int main()
54
55 //]
56
57 /* Output
58
59 policy_eg_1.cpp
60 Generating code
61 Finished generating code
62 policy_eg_1.vcxproj -> J:\Cpp\MathToolkit\test\Math_test\Release\policy_eg_1.exe
63 Result of tgamma(30000) is: 1.#INF
64 errno = 34
65 Result of tgamma(-10) is: 1.#QNAN
66 errno = 33
67
68 */
69
70