1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/random/lognormal_distribution.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,114 @@
1.4 +/* boost random/lognormal_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: lognormal_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_LOGNORMAL_DISTRIBUTION_HPP
1.20 +#define BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP
1.21 +
1.22 +#include <cmath> // std::exp, std::sqrt
1.23 +#include <cassert>
1.24 +#include <iostream>
1.25 +#include <boost/limits.hpp>
1.26 +#include <boost/static_assert.hpp>
1.27 +#include <boost/random/normal_distribution.hpp>
1.28 +
1.29 +#ifdef BOOST_NO_STDC_NAMESPACE
1.30 +namespace std {
1.31 + using ::log;
1.32 + using ::sqrt;
1.33 +}
1.34 +#endif
1.35 +
1.36 +namespace boost {
1.37 +
1.38 +#if defined(__GNUC__) && (__GNUC__ < 3)
1.39 +// Special gcc workaround: gcc 2.95.x ignores using-declarations
1.40 +// in template classes (confirmed by gcc author Martin v. Loewis)
1.41 + using std::sqrt;
1.42 + using std::exp;
1.43 +#endif
1.44 +
1.45 +template<class RealType = double>
1.46 +class lognormal_distribution
1.47 +{
1.48 +public:
1.49 + typedef typename normal_distribution<RealType>::input_type input_type;
1.50 + typedef RealType result_type;
1.51 +
1.52 +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
1.53 + BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
1.54 +#endif
1.55 +
1.56 + explicit lognormal_distribution(result_type mean = result_type(1),
1.57 + result_type sigma = result_type(1))
1.58 + : _mean(mean), _sigma(sigma)
1.59 + {
1.60 + assert(mean > result_type(0));
1.61 + init();
1.62 + }
1.63 +
1.64 + // compiler-generated copy ctor and assignment operator are fine
1.65 +
1.66 + RealType& mean() const { return _mean; }
1.67 + RealType& sigma() const { return _sigma; }
1.68 + void reset() { _normal.reset(); }
1.69 +
1.70 + template<class Engine>
1.71 + result_type operator()(Engine& eng)
1.72 + {
1.73 +#ifndef BOOST_NO_STDC_NAMESPACE
1.74 + // allow for Koenig lookup
1.75 + using std::exp;
1.76 +#endif
1.77 + return exp(_normal(eng) * _nsigma + _nmean);
1.78 + }
1.79 +
1.80 +#if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
1.81 + template<class CharT, class Traits>
1.82 + friend std::basic_ostream<CharT,Traits>&
1.83 + operator<<(std::basic_ostream<CharT,Traits>& os, const lognormal_distribution& ld)
1.84 + {
1.85 + os << ld._normal << " " << ld._mean << " " << ld._sigma;
1.86 + return os;
1.87 + }
1.88 +
1.89 + template<class CharT, class Traits>
1.90 + friend std::basic_istream<CharT,Traits>&
1.91 + operator>>(std::basic_istream<CharT,Traits>& is, lognormal_distribution& ld)
1.92 + {
1.93 + is >> std::ws >> ld._normal >> std::ws >> ld._mean >> std::ws >> ld._sigma;
1.94 + ld.init();
1.95 + return is;
1.96 + }
1.97 +#endif
1.98 +
1.99 +private:
1.100 + void init()
1.101 + {
1.102 +#ifndef BOOST_NO_STDC_NAMESPACE
1.103 + // allow for Koenig lookup
1.104 + using std::exp; using std::log; using std::sqrt;
1.105 +#endif
1.106 + _nmean = log(_mean*_mean/sqrt(_sigma*_sigma + _mean*_mean));
1.107 + _nsigma = sqrt(log(_sigma*_sigma/_mean/_mean+result_type(1)));
1.108 + }
1.109 +
1.110 + RealType _mean, _sigma;
1.111 + RealType _nmean, _nsigma;
1.112 + normal_distribution<result_type> _normal;
1.113 +};
1.114 +
1.115 +} // namespace boost
1.116 +
1.117 +#endif // BOOST_RANDOM_LOGNORMAL_DISTRIBUTION_HPP