]> git.donarmstrong.com Git - rsem.git/blob - boost/random/exponential_distribution.hpp
022faef8f61e5040997f6b90198abb3b2377828f
[rsem.git] / boost / random / exponential_distribution.hpp
1 /* boost random/exponential_distribution.hpp header file
2  *
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)
7  *
8  * See http://www.boost.org for most recent version including documentation.
9  *
10  * $Id: exponential_distribution.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $
11  *
12  * Revision history
13  *  2001-02-18  moved to individual header files
14  */
15
16 #ifndef BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
17 #define BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
18
19 #include <boost/config/no_tr1/cmath.hpp>
20 #include <cassert>
21 #include <iostream>
22 #include <boost/limits.hpp>
23 #include <boost/static_assert.hpp>
24 #include <boost/random/detail/config.hpp>
25
26 namespace boost {
27
28 /**
29  * The exponential distribution has a single parameter lambda.
30  *
31  * It has \f$p(x) = \lambda e^{-\lambda x}\f$
32  */
33 template<class RealType = double>
34 class exponential_distribution
35 {
36 public:
37   typedef RealType input_type;
38   typedef RealType result_type;
39
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);
42 #endif
43
44   explicit exponential_distribution(result_type lambda_arg = result_type(1))
45     : _lambda(lambda_arg) { assert(_lambda > result_type(0)); }
46
47   // compiler-generated copy ctor and assignment operator are fine
48
49   result_type lambda() const { return _lambda; }
50
51   void reset() { }
52
53   template<class Engine>
54   result_type operator()(Engine& eng)
55   { 
56 #ifndef BOOST_NO_STDC_NAMESPACE
57     using std::log;
58 #endif
59     return -result_type(1) / _lambda * log(result_type(1)-eng());
60   }
61
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)
66   {
67     os << ed._lambda;
68     return os;
69   }
70
71   template<class CharT, class Traits>
72   friend std::basic_istream<CharT,Traits>&
73   operator>>(std::basic_istream<CharT,Traits>& is, exponential_distribution& ed)
74   {
75     is >> std::ws >> ed._lambda;
76     return is;
77   }
78 #endif
79
80 private:
81   result_type _lambda;
82 };
83
84 } // namespace boost
85
86 #endif // BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP