epoc32/include/stdapis/boost/random/exponential_distribution.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/random/exponential_distribution.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,81 @@
     1.4 +/* boost random/exponential_distribution.hpp header file
     1.5 + *
     1.6 + * Copyright Jens Maurer 2000-2001
     1.7 + * Distributed under the Boost Software License, Version 1.0. (See
     1.8 + * accompanying file LICENSE_1_0.txt or copy at
     1.9 + * http://www.boost.org/LICENSE_1_0.txt)
    1.10 + *
    1.11 + * See http://www.boost.org for most recent version including documentation.
    1.12 + *
    1.13 + * $Id: exponential_distribution.hpp,v 1.16 2004/07/27 03:43:32 dgregor Exp $
    1.14 + *
    1.15 + * Revision history
    1.16 + *  2001-02-18  moved to individual header files
    1.17 + */
    1.18 +
    1.19 +#ifndef BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
    1.20 +#define BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP
    1.21 +
    1.22 +#include <cmath>
    1.23 +#include <cassert>
    1.24 +#include <iostream>
    1.25 +#include <boost/limits.hpp>
    1.26 +#include <boost/static_assert.hpp>
    1.27 +
    1.28 +namespace boost {
    1.29 +
    1.30 +// exponential distribution: p(x) = lambda * exp(-lambda * x)
    1.31 +template<class RealType = double>
    1.32 +class exponential_distribution
    1.33 +{
    1.34 +public:
    1.35 +  typedef RealType input_type;
    1.36 +  typedef RealType result_type;
    1.37 +
    1.38 +#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300)
    1.39 +  BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
    1.40 +#endif
    1.41 +
    1.42 +  explicit exponential_distribution(result_type lambda = result_type(1))
    1.43 +    : _lambda(lambda) { assert(lambda > result_type(0)); }
    1.44 +
    1.45 +  // compiler-generated copy ctor and assignment operator are fine
    1.46 +
    1.47 +  result_type lambda() const { return _lambda; }
    1.48 +
    1.49 +  void reset() { }
    1.50 +
    1.51 +  template<class Engine>
    1.52 +  result_type operator()(Engine& eng)
    1.53 +  { 
    1.54 +#ifndef BOOST_NO_STDC_NAMESPACE
    1.55 +    using std::log;
    1.56 +#endif
    1.57 +    return -result_type(1) / _lambda * log(result_type(1)-eng());
    1.58 +  }
    1.59 +
    1.60 +#if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
    1.61 +  template<class CharT, class Traits>
    1.62 +  friend std::basic_ostream<CharT,Traits>&
    1.63 +  operator<<(std::basic_ostream<CharT,Traits>& os, const exponential_distribution& ed)
    1.64 +  {
    1.65 +    os << ed._lambda;
    1.66 +    return os;
    1.67 +  }
    1.68 +
    1.69 +  template<class CharT, class Traits>
    1.70 +  friend std::basic_istream<CharT,Traits>&
    1.71 +  operator>>(std::basic_istream<CharT,Traits>& is, exponential_distribution& ed)
    1.72 +  {
    1.73 +    is >> std::ws >> ed._lambda;
    1.74 +    return is;
    1.75 +  }
    1.76 +#endif
    1.77 +
    1.78 +private:
    1.79 +  result_type _lambda;
    1.80 +};
    1.81 +
    1.82 +} // namespace boost
    1.83 +
    1.84 +#endif // BOOST_RANDOM_EXPONENTIAL_DISTRIBUTION_HPP