mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
Avoid name ambiguity.
[SVN r65128]
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// example_policy_handling.cpp
|
||||
|
||||
// Copyright Paul A. Bristow 2007.
|
||||
// Copyright Paul A. Bristow 2007, 2010.
|
||||
// Copyright John Maddock 2007.
|
||||
|
||||
// Use, modification and distribution are subject to the
|
||||
@@ -14,13 +14,17 @@
|
||||
// for student's t distribution CDF,
|
||||
// and catching the exception.
|
||||
|
||||
// See error_handling_policies for more examples.
|
||||
// See error_handling_policies.cpp for more examples.
|
||||
|
||||
// Boost
|
||||
#include <boost/math/distributions/students_t.hpp>
|
||||
using boost::math::students_t_distribution; // Probability of students_t(df, t).
|
||||
using boost::math::students_t; // Probability of students_t(df, t) convenience typedef for double.
|
||||
|
||||
using boost::math::policies::policy;
|
||||
using boost::math::policies::domain_error;
|
||||
using boost::math::policies::ignore_error;
|
||||
|
||||
// std
|
||||
#include <iostream>
|
||||
using std::cout;
|
||||
@@ -29,16 +33,12 @@ using boost::math::students_t; // Probability of students_t(df, t) convenience
|
||||
#include <stdexcept>
|
||||
using std::exception;
|
||||
|
||||
using boost::math::policies::policy;
|
||||
using boost::math::policies::domain_error;
|
||||
using boost::math::policies::ignore_error;
|
||||
|
||||
// Define a (bad?) policy to ignore domain errors ('bad' arguments):
|
||||
typedef policy<
|
||||
domain_error<ignore_error>
|
||||
> my_policy;
|
||||
|
||||
// Define my distribution with this different domain error policy:
|
||||
// Define my_students_t distribution with this different domain error policy:
|
||||
typedef students_t_distribution<double, my_policy> my_students_t;
|
||||
|
||||
int main()
|
||||
@@ -49,15 +49,16 @@ int main()
|
||||
|
||||
try
|
||||
{
|
||||
cout << "Probability of ignore_error Student's t is " << cdf(my_students_t(degrees_of_freedom), t) << endl;
|
||||
cout << "Probability of ignore_error Student's t is "
|
||||
<< cdf(my_students_t(degrees_of_freedom), t) << endl;
|
||||
cout << "Probability of default error policy Student's t is " << endl;
|
||||
// BY contrast the students_t distribution default domain error policy is to throw,
|
||||
// By contrast the students_t distribution default domain error policy is to throw,
|
||||
cout << cdf(students_t(-1), -1) << endl; // so this will throw.
|
||||
/*`
|
||||
/*`
|
||||
Message from thrown exception was:
|
||||
Error in function boost::math::students_t_distribution<double>::students_t_distribution:
|
||||
Degrees of freedom argument is -1, but must be > 0 !
|
||||
*/
|
||||
*/
|
||||
|
||||
// We could also define a 'custom' distribution
|
||||
// with an "ignore overflow error policy" in a single statement:
|
||||
@@ -78,11 +79,15 @@ int main()
|
||||
|
||||
Output:
|
||||
|
||||
Example error handling using Student's t function.
|
||||
Probability of ignore_error Student's t is 1.#QNAN
|
||||
Probability of default error policy Student's t is
|
||||
Message from thrown exception was:
|
||||
Error in function boost::math::students_t_distribution<double>::students_t_distribution:
|
||||
Degrees of freedom argument is -1, but must be > 0 !
|
||||
error_policy_example.cpp
|
||||
Generating code
|
||||
Finished generating code
|
||||
error_policy_example.vcxproj -> J:\Cpp\MathToolkit\test\Math_test\Release\error_policy_example.exe
|
||||
Example error handling using Student's t function.
|
||||
Probability of ignore_error Student's t is 1.#QNAN
|
||||
Probability of default error policy Student's t is
|
||||
|
||||
Message from thrown exception was:
|
||||
Error in function boost::math::students_t_distribution<double>::students_t_distribution: Degrees of freedom argument is -1, but must be > 0 !
|
||||
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user