|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65153 - trunk/libs/math/example
From: pbristow_at_[hidden]
Date: 2010-08-31 14:12:56
Author: pbristow
Date: 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
New Revision: 65153
URL: http://svn.boost.org/trac/boost/changeset/65153
Log:
Avoid name ambiguity, etc
Text files modified:
trunk/libs/math/example/binomial_quiz_example.cpp | 8 +++-
trunk/libs/math/example/find_scale_example.cpp | 2
trunk/libs/math/example/laplace_example.cpp | 4 -
trunk/libs/math/example/nc_chi_sq_example.cpp | 6 +++
trunk/libs/math/example/neg_binom_confidence_limits.cpp | 2
trunk/libs/math/example/neg_binomial_sample_sizes.cpp | 3 +
trunk/libs/math/example/negative_binomial_example1.cpp | 2
trunk/libs/math/example/negative_binomial_example2.cpp | 2
trunk/libs/math/example/normal_misc_examples.cpp | 5 --
trunk/libs/math/example/policy_eg_2.cpp | 24 +++++++++++++-
trunk/libs/math/example/policy_eg_3.cpp | 41 +++++++++++++++++--------
trunk/libs/math/example/policy_eg_4.cpp | 63 +++++++++++++++++++++------------------
12 files changed, 103 insertions(+), 59 deletions(-)
Modified: trunk/libs/math/example/binomial_quiz_example.cpp
==============================================================================
--- trunk/libs/math/example/binomial_quiz_example.cpp (original)
+++ trunk/libs/math/example/binomial_quiz_example.cpp 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
@@ -1,4 +1,4 @@
-// Copyright Paul A. Bristow 2007, 2009
+// Copyright Paul A. Bristow 2007, 2009, 2010
// Copyright John Maddock 2006
// Use, modification and distribution are subject to the
@@ -38,6 +38,10 @@
using std::ios; using std::flush; using std::left; using std::right; using std::fixed;
#include <iomanip>
using std::setw; using std::setprecision;
+#include <exception>
+ using std::exception;
+
+
//][/binomial_quiz_example1]
int main()
@@ -406,7 +410,7 @@
//] [/discrete_quantile_real]
}
- catch(const std::exception& e)
+ catch(const exception& e)
{ // Always useful to include try & catch blocks because
// default policies are to throw exceptions on arguments that cause
// errors like underflow, overflow.
Modified: trunk/libs/math/example/find_scale_example.cpp
==============================================================================
--- trunk/libs/math/example/find_scale_example.cpp (original)
+++ trunk/libs/math/example/find_scale_example.cpp 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
@@ -1,6 +1,6 @@
// find_scale.cpp
-// Copyright Paul A. Bristow 2007.
+// Copyright Paul A. Bristow 2007, 2010.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
Modified: trunk/libs/math/example/laplace_example.cpp
==============================================================================
--- trunk/libs/math/example/laplace_example.cpp (original)
+++ trunk/libs/math/example/laplace_example.cpp 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
@@ -1,6 +1,6 @@
// laplace_example.cpp
-// Copyright Paul A. Bristow 2008.
+// Copyright Paul A. Bristow 2008, 2010.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
@@ -128,7 +128,6 @@
return 0;
} // int main()
-
/*
Output is:
@@ -166,6 +165,5 @@
95% of gaussian area has a z between 1.95996 and -1.95996
95% of laplace area has a z between 2.99573 and -2.99573
-
*/
Modified: trunk/libs/math/example/nc_chi_sq_example.cpp
==============================================================================
--- trunk/libs/math/example/nc_chi_sq_example.cpp (original)
+++ trunk/libs/math/example/nc_chi_sq_example.cpp 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
@@ -1,4 +1,5 @@
// Copyright John Maddock 2008
+// Copyright Paul A. Bristow 2010
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
@@ -24,7 +25,12 @@
*/
#include <boost/math/distributions/non_central_chi_squared.hpp>
+using boost::math::chi_squared;
+boost::math::non_central_chi_squared;
+
#include <iostream>
+using std::cout; using std::endl;
+using std::setprecision;
int main()
{
Modified: trunk/libs/math/example/neg_binom_confidence_limits.cpp
==============================================================================
--- trunk/libs/math/example/neg_binom_confidence_limits.cpp (original)
+++ trunk/libs/math/example/neg_binom_confidence_limits.cpp 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
@@ -1,7 +1,7 @@
// neg_binomial_confidence_limits.cpp
// Copyright John Maddock 2006
-// Copyright Paul A. Bristow 2007
+// Copyright Paul A. Bristow 2007, 2010
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
Modified: trunk/libs/math/example/neg_binomial_sample_sizes.cpp
==============================================================================
--- trunk/libs/math/example/neg_binomial_sample_sizes.cpp (original)
+++ trunk/libs/math/example/neg_binomial_sample_sizes.cpp 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
@@ -1,7 +1,8 @@
// neg_binomial_sample_sizes.cpp
-// Copyright Paul A. Bristow 2007
// Copyright John Maddock 2006
+// Copyright Paul A. Bristow 2007, 2010
+
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
Modified: trunk/libs/math/example/negative_binomial_example1.cpp
==============================================================================
--- trunk/libs/math/example/negative_binomial_example1.cpp (original)
+++ trunk/libs/math/example/negative_binomial_example1.cpp 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
@@ -1,6 +1,6 @@
// negative_binomial_example1.cpp
-// Copyright Paul A. Bristow 2007.
+// Copyright Paul A. Bristow 2007, 2010.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
Modified: trunk/libs/math/example/negative_binomial_example2.cpp
==============================================================================
--- trunk/libs/math/example/negative_binomial_example2.cpp (original)
+++ trunk/libs/math/example/negative_binomial_example2.cpp 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
@@ -1,6 +1,6 @@
// negative_binomial_example2.cpp
-// Copyright Paul A. Bristow 2007.
+// Copyright Paul A. Bristow 2007, 2010.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
Modified: trunk/libs/math/example/normal_misc_examples.cpp
==============================================================================
--- trunk/libs/math/example/normal_misc_examples.cpp (original)
+++ trunk/libs/math/example/normal_misc_examples.cpp 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
@@ -1,6 +1,6 @@
// normal_misc_examples.cpp
-// Copyright Paul A. Bristow 2007.
+// Copyright Paul A. Bristow 2007, 2010.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
@@ -504,6 +504,3 @@
95% of bolts are shorter than 4.11
*/
-
-
-
Modified: trunk/libs/math/example/policy_eg_2.cpp
==============================================================================
--- trunk/libs/math/example/policy_eg_2.cpp (original)
+++ trunk/libs/math/example/policy_eg_2.cpp 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
@@ -1,17 +1,27 @@
// Copyright John Maddock 2007.
+// Copyright Paul A. Bristow 2010
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <iostream>
+using std::cout; using std::endl;
//[policy_eg_2
#include <boost/math/special_functions/gamma.hpp>
+using boost::math::tgamma;
int main()
{
- using namespace boost::math::policies;
+ // using namespace boost::math::policies; // or
+ using boost::math::policies::errno_on_error;
+ using boost::math::policies::make_policy;
+ using boost::math::policies::pole_error;
+ using boost::math::policies::domain_error;
+ using boost::math::policies::overflow_error;
+ using boost::math::policies::evaluation_error;
+
errno = 0;
std::cout << "Result of tgamma(30000) is: "
<< boost::math::tgamma(
@@ -40,5 +50,15 @@
std::cout << "errno = " << errno << std::endl;
}
-//]
+//] //[/policy_eg_2]
+
+/*
+
+Output:
+
+ Result of tgamma(30000) is: 1.#INF
+ errno = 34
+ Result of tgamma(-10) is: 1.#QNAN
+ errno = 33
+*/
Modified: trunk/libs/math/example/policy_eg_3.cpp
==============================================================================
--- trunk/libs/math/example/policy_eg_3.cpp (original)
+++ trunk/libs/math/example/policy_eg_3.cpp 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
@@ -1,5 +1,5 @@
// Copyright John Maddock 2007.
-// Copyright Paul A. Bristow 2007.
+// Copyright Paul A. Bristow 2007, 2010.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
@@ -11,32 +11,45 @@
#endif
#include <iostream>
+using std::cout; using std::endl;
//[policy_eg_3
#include <boost/math/distributions/binomial.hpp>
+using boost::math::binomial_distribution;
+
+// Begin by defining a policy type, that gives the behaviour we want:
+
+//using namespace boost::math::policies; or explicitly
+using boost::math::policies::policy;
+
+using boost::math::policies::promote_float;
+using boost::math::policies::discrete_quantile;
+using boost::math::policies::integer_round_nearest;
-//
-// Begin by defining a policy type, that gives the
-// behaviour we want:
-//
-using namespace boost::math::policies;
typedef policy<
- promote_float<false>,
- discrete_quantile<integer_round_nearest>
+ promote_float<false>, // Do not promote to double.
+ discrete_quantile<integer_round_nearest> // Round result to nearest integer.
> mypolicy;
//
-// Then define a distribution that uses it:
-//
+// Then define a new distribution that uses it:
typedef boost::math::binomial_distribution<float, mypolicy> mybinom;
-//
+
// And now use it to get the quantile:
-//
+
int main()
{
- std::cout << "quantile is: " <<
- quantile(mybinom(200, 0.25), 0.05) << std::endl;
+ cout << "quantile(mybinom(200, 0.25), 0.05) is: " <<
+ quantile(mybinom(200, 0.25), 0.05) << endl;
}
//]
+/*
+
+Output:
+
+ quantile(mybinom(200, 0.25), 0.05) is: 40
+
+*/
+
Modified: trunk/libs/math/example/policy_eg_4.cpp
==============================================================================
--- trunk/libs/math/example/policy_eg_4.cpp (original)
+++ trunk/libs/math/example/policy_eg_4.cpp 2010-08-31 14:12:53 EDT (Tue, 31 Aug 2010)
@@ -1,4 +1,6 @@
// Copyright John Maddock 2007.
+// Copyright Paul A. Bristow 2010
+
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -7,6 +9,7 @@
// and comments, don't change any of the special comment mark-ups!
#include <iostream>
+using std::cout; using std::endl;
//[policy_eg_4
@@ -18,32 +21,37 @@
*/
#include <boost/math/special_functions.hpp>
+using boost::math::tgamma;
/*`
-
Open up the "C" namespace that we'll use for our functions, and
define the policy type we want: in this case one that sets
-::errno rather than throwing exceptions. Any policies we don't
-specify here will inherit the defaults:
+::errno and returns a standard value, rather than throwing exceptions.
+Any policies we don't specify here will inherit the defaults.
*/
-namespace C{
-
-using namespace boost::math::policies;
+namespace C
+{
+ //using namespace boost::math::policies; or explicitly:
+ using boost::math::policies::policy;
-typedef policy<
- domain_error<errno_on_error>,
- pole_error<errno_on_error>,
- overflow_error<errno_on_error>,
- evaluation_error<errno_on_error>
-> c_policy;
+ using boost::math::policies::domain_error;
+ using boost::math::policies::pole_error;
+ using boost::math::policies::overflow_error;
+ using boost::math::policies::evaluation_error;
+ using boost::math::policies::errno_on_error;
+
+ typedef policy<
+ domain_error<errno_on_error>,
+ pole_error<errno_on_error>,
+ overflow_error<errno_on_error>,
+ evaluation_error<errno_on_error>
+ > c_policy;
/*`
-
All we need do now is invoke the BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS
-macro passing our policy type as the single argument:
-
+macro passing our policy type c_policy as the single argument:
*/
BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS(c_policy)
@@ -51,7 +59,6 @@
} // close namespace C
/*`
-
We now have a set of forwarding functions defined in namespace C
that all look something like this:
@@ -64,21 +71,20 @@
}
``
-So that when we call `C::tgamma(z)` we really end up calling
+So that when we call `C::tgamma(z)`, we really end up calling
`boost::math::tgamma(z, C::c_policy())`:
-
*/
int main()
{
errno = 0;
- std::cout << "Result of tgamma(30000) is: "
- << C::tgamma(30000) << std::endl;
- std::cout << "errno = " << errno << std::endl;
- std::cout << "Result of tgamma(-10) is: "
- << C::tgamma(-10) << std::endl;
- std::cout << "errno = " << errno << std::endl;
+ cout << "Result of tgamma(30000) is: "
+ << C::tgamma(30000) << endl;
+ cout << "errno = " << errno << endl; // errno = 34
+ cout << "Result of tgamma(-10) is: "
+ << C::tgamma(-10) << endl;
+ cout << "errno = " << errno << endl; // errno = 33, overwriting previous value of 34.
}
/*`
@@ -92,11 +98,10 @@
errno = 33
]
-This mechanism is particularly useful when we want to define a
-project-wide policy, and don't want to modify the Boost source
-or set - possibly fragile and easy to forget - project wide
-build macros.
+This mechanism is particularly useful when we want to define a project-wide policy,
+and don't want to modify the Boost source,
+or to set project wide build macros (possibly fragile and easy to forget).
*/
-//]
+//] //[/policy_eg_4]
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