Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65128 - trunk/libs/math/example
From: pbristow_at_[hidden]
Date: 2010-08-30 05:30:58


Author: pbristow
Date: 2010-08-30 05:30:55 EDT (Mon, 30 Aug 2010)
New Revision: 65128
URL: http://svn.boost.org/trac/boost/changeset/65128

Log:
Avoid name ambiguity.
Text files modified:
   trunk/libs/math/example/error_policies_example.cpp | 25 +++++++++++++++----------
   trunk/libs/math/example/error_policy_example.cpp | 39 ++++++++++++++++++++++-----------------
   2 files changed, 37 insertions(+), 27 deletions(-)

Modified: trunk/libs/math/example/error_policies_example.cpp
==============================================================================
--- trunk/libs/math/example/error_policies_example.cpp (original)
+++ trunk/libs/math/example/error_policies_example.cpp 2010-08-30 05:30:55 EDT (Mon, 30 Aug 2010)
@@ -1,6 +1,6 @@
 // error_policies_example.cpp
 
-// Copyright Paul A. Bristow 2007.
+// Copyright Paul A. Bristow 2007, 2010.
 // Copyright John Maddock 2007.
 
 // Use, modification and distribution are subject to the
@@ -15,12 +15,13 @@
    using boost::math::students_t; // Probability of students_t(df, t).
    using boost::math::students_t_distribution;
 
-// using namespace boost::math;
+// using namespace boost::math; causes:
 //.\error_policy_normal.cpp(30) : error C2872: 'policy' : ambiguous symbol
-// could be 'I:\Boost-sandbox\math_toolkit\boost/math/policies/policy.hpp(392) : boost::math::policies::policy'
+// could be '\boost/math/policies/policy.hpp(392) : boost::math::policies::policy'
 // or 'boost::math::policies'
 
- // So can't use this using namespace command.
+// So should not use this 'using namespace boost::math;' command.
+
 // Suppose we want a statistical distribution to return infinities,
 // rather than throw exceptions (the default policy), then we can use:
 
@@ -89,11 +90,15 @@
 
 Output:
 
-quantile(my_normal(), 0.05); = -1.64485
-quantile(my_normal(), 0.); = -1.#INF
-quantile(my_normal(), 0.); = -1.#INF
-quantile(my_students_t(), 0.); = 1.#QNAN
-quantile(my_normal2(), 0.); = -2.32635
-quantile(my_normal2(), 0.); = -1.#INF
+error_policies_example.cpp
+ Generating code
+ Finished generating code
+ error_policy_normal_example.vcxproj -> J:\Cpp\MathToolkit\test\Math_test\Release\error_policies_example.exe
+ quantile(my_normal(), 0.05); = -1.64485
+ quantile(my_normal(), 0.); = -1.#INF
+ quantile(my_normal(), 0.); = -1.#INF
+ quantile(my_students_t(), 0.); = 1.#QNAN
+ quantile(my_normal2(), 0.); = -2.32635
+ quantile(my_normal2(), 0.); = -1.#INF
 
 */

Modified: trunk/libs/math/example/error_policy_example.cpp
==============================================================================
--- trunk/libs/math/example/error_policy_example.cpp (original)
+++ trunk/libs/math/example/error_policy_example.cpp 2010-08-30 05:30:55 EDT (Mon, 30 Aug 2010)
@@ -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 @@
 #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 @@
 
   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 @@
 
 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 !
 
 */


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk