1 /* boost random/poisson_distribution.hpp header file
\r
3 * Copyright Jens Maurer 2002
\r
4 * Distributed under the Boost Software License, Version 1.0. (See
\r
5 * accompanying file LICENSE_1_0.txt or copy at
\r
6 * http://www.boost.org/LICENSE_1_0.txt)
\r
8 * See http://www.boost.org for most recent version including documentation.
\r
10 * $Id: poisson_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $
\r
14 #ifndef BOOST_RANDOM_POISSON_DISTRIBUTION_HPP
\r
15 #define BOOST_RANDOM_POISSON_DISTRIBUTION_HPP
\r
17 #include <boost/config/no_tr1/cmath.hpp>
\r
20 #include <boost/limits.hpp>
\r
21 #include <boost/static_assert.hpp>
\r
22 #include <boost/random/detail/config.hpp>
\r
27 template<class IntType = int, class RealType = double>
\r
28 class poisson_distribution
\r
31 typedef RealType input_type;
\r
32 typedef IntType result_type;
\r
34 explicit poisson_distribution(const RealType& mean_arg = RealType(1))
\r
37 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
\r
38 // MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
\r
39 BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
\r
40 BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
\r
43 assert(_mean > RealType(0));
\r
47 // compiler-generated copy ctor and assignment operator are fine
\r
49 RealType mean() const { return _mean; }
\r
52 template<class Engine>
\r
53 result_type operator()(Engine& eng)
\r
55 // TODO: This is O(_mean), but it should be O(log(_mean)) for large _mean
\r
56 RealType product = RealType(1);
\r
57 for(result_type m = 0; ; ++m) {
\r
59 if(product <= _exp_mean)
\r
64 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
\r
65 template<class CharT, class Traits>
\r
66 friend std::basic_ostream<CharT,Traits>&
\r
67 operator<<(std::basic_ostream<CharT,Traits>& os, const poisson_distribution& pd)
\r
73 template<class CharT, class Traits>
\r
74 friend std::basic_istream<CharT,Traits>&
\r
75 operator>>(std::basic_istream<CharT,Traits>& is, poisson_distribution& pd)
\r
77 is >> std::ws >> pd._mean;
\r
86 #ifndef BOOST_NO_STDC_NAMESPACE
\r
87 // allow for Koenig lookup
\r
90 _exp_mean = exp(-_mean);
\r
94 // some precomputed data from the parameters
\r
98 } // namespace boost
\r
100 #endif // BOOST_RANDOM_POISSON_DISTRIBUTION_HPP
\r