1 /* boost random/exponential_distribution.hpp header file
\r
3 * Copyright Jens Maurer 2000-2001
\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: exponential_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $
\r
13 * 2001-02-18 moved to individual header files
\r
16 #ifndef BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
\r
17 #define BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
\r
19 #include <boost/config/no_tr1/cmath.hpp>
\r
22 #include <boost/limits.hpp>
\r
23 #include <boost/static_assert.hpp>
\r
24 #include <boost/random/detail/config.hpp>
\r
28 // exponential distribution: p(x) = lambda * exp(-lambda * x)
\r
29 template<class RealType = double>
\r
30 class exponential_distribution
\r
33 typedef RealType input_type;
\r
34 typedef RealType result_type;
\r
36 #if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300)
\r
37 BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
\r
40 explicit exponential_distribution(result_type lambda_arg = result_type(1))
\r
41 : _lambda(lambda_arg) { assert(_lambda > result_type(0)); }
\r
43 // compiler-generated copy ctor and assignment operator are fine
\r
45 result_type lambda() const { return _lambda; }
\r
49 template<class Engine>
\r
50 result_type operator()(Engine& eng)
\r
52 #ifndef BOOST_NO_STDC_NAMESPACE
\r
55 return -result_type(1) / _lambda * log(result_type(1)-eng());
\r
58 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
\r
59 template<class CharT, class Traits>
\r
60 friend std::basic_ostream<CharT,Traits>&
\r
61 operator<<(std::basic_ostream<CharT,Traits>& os, const exponential_distribution& ed)
\r
67 template<class CharT, class Traits>
\r
68 friend std::basic_istream<CharT,Traits>&
\r
69 operator>>(std::basic_istream<CharT,Traits>& is, exponential_distribution& ed)
\r
71 is >> std::ws >> ed._lambda;
\r
77 result_type _lambda;
\r
80 } // namespace boost
\r
82 #endif // BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
\r