1 /* boost random/exponential_distribution.hpp header file
3 * Copyright Jens Maurer 2000-2001
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
8 * See http://www.boost.org for most recent version including documentation.
10 * $Id: exponential_distribution.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
13 * 2001-02-18 moved to individual header files
16 #ifndef BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
17 #define BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
19 #include <boost/config/no_tr1/cmath.hpp>
22 #include <boost/limits.hpp>
23 #include <boost/static_assert.hpp>
24 #include <boost/random/detail/config.hpp>
29 * The exponential distribution has a single parameter lambda.
31 * It has \f$p(x) = \lambda e^{-\lambda x}\f$
33 template<class RealType = double>
34 class exponential_distribution
37 typedef RealType input_type;
38 typedef RealType result_type;
40 #if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300)
41 BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
44 explicit exponential_distribution(result_type lambda_arg = result_type(1))
45 : _lambda(lambda_arg) { assert(_lambda > result_type(0)); }
47 // compiler-generated copy ctor and assignment operator are fine
49 result_type lambda() const { return _lambda; }
53 template<class Engine>
54 result_type operator()(Engine& eng)
56 #ifndef BOOST_NO_STDC_NAMESPACE
59 return -result_type(1) / _lambda * log(result_type(1)-eng());
62 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
63 template<class CharT, class Traits>
64 friend std::basic_ostream<CharT,Traits>&
65 operator<<(std::basic_ostream<CharT,Traits>& os, const exponential_distribution& ed)
71 template<class CharT, class Traits>
72 friend std::basic_istream<CharT,Traits>&
73 operator>>(std::basic_istream<CharT,Traits>& is, exponential_distribution& ed)
75 is >> std::ws >> ed._lambda;
86 #endif // BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP