2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Avoid name ambiguity, etc

[SVN r65153]
This commit is contained in:
Paul A. Bristow
2010-08-31 18:12:53 +00:00
parent d518687b2a
commit 2e3e4c4b07
12 changed files with 102 additions and 58 deletions

View File

@@ -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 @@ First, we need to be able to use the binomial distribution constructor
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 @@ If guessing then percentiles 1 to 99% will get 0 to 7.788 right.
//] [/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.

View File

@@ -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.

View File

@@ -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 @@ is 0.05 = 1 - 0.95 (for a one-sided test), so we can write
return 0;
} // int main()
/*
Output is:
@@ -166,6 +165,5 @@ Area for laplace z = 2 is 0.932332
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
*/

View File

@@ -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 @@ First we need some includes to access the non-central chi squared distribution
*/
#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()
{

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -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.

View File

@@ -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 @@ Fraction too long [ P(X > 4.10) ] is 0.0668
95% of bolts are shorter than 4.11
*/

View File

@@ -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 @@ int main()
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
*/

View File

@@ -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
*/

View File

@@ -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 @@ We'll begin by including the needed header:
*/
#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{
namespace C
{
//using namespace boost::math::policies; or explicitly:
using boost::math::policies::policy;
using namespace boost::math::policies;
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;
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 @@ BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS(c_policy)
} // 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 @@ inline typename boost::math::tools::promote_args<RT>::type
}
``
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 @@ Result of C::tgamma(-10) is: 1.#QNAN
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]