1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/random/cauchy_distribution.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,89 @@
1.4 +/* boost random/cauchy_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: cauchy_distribution.hpp,v 1.15 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_CAUCHY_DISTRIBUTION_HPP
1.20 +#define BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP
1.21 +
1.22 +#include <cmath>
1.23 +#include <iostream>
1.24 +#include <boost/limits.hpp>
1.25 +#include <boost/static_assert.hpp>
1.26 +
1.27 +namespace boost {
1.28 +
1.29 +#if defined(__GNUC__) && (__GNUC__ < 3)
1.30 +// Special gcc workaround: gcc 2.95.x ignores using-declarations
1.31 +// in template classes (confirmed by gcc author Martin v. Loewis)
1.32 + using std::tan;
1.33 +#endif
1.34 +
1.35 +// Cauchy distribution: p(x) = sigma/(pi*(sigma**2 + (x-median)**2))
1.36 +template<class RealType = double>
1.37 +class cauchy_distribution
1.38 +{
1.39 +public:
1.40 + typedef RealType input_type;
1.41 + typedef RealType result_type;
1.42 +
1.43 +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
1.44 + BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
1.45 +#endif
1.46 +
1.47 + explicit cauchy_distribution(result_type median = result_type(0),
1.48 + result_type sigma = result_type(1))
1.49 + : _median(median), _sigma(sigma) { }
1.50 +
1.51 + // compiler-generated copy ctor and assignment operator are fine
1.52 +
1.53 + result_type median() const { return _median; }
1.54 + result_type sigma() const { return _sigma; }
1.55 + void reset() { }
1.56 +
1.57 + template<class Engine>
1.58 + result_type operator()(Engine& eng)
1.59 + {
1.60 + // Can we have a boost::mathconst please?
1.61 + const result_type pi = result_type(3.14159265358979323846);
1.62 +#ifndef BOOST_NO_STDC_NAMESPACE
1.63 + using std::tan;
1.64 +#endif
1.65 + return _median + _sigma * tan(pi*(eng()-result_type(0.5)));
1.66 + }
1.67 +
1.68 +#if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
1.69 + template<class CharT, class Traits>
1.70 + friend std::basic_ostream<CharT,Traits>&
1.71 + operator<<(std::basic_ostream<CharT,Traits>& os, const cauchy_distribution& cd)
1.72 + {
1.73 + os << cd._median << " " << cd._sigma;
1.74 + return os;
1.75 + }
1.76 +
1.77 + template<class CharT, class Traits>
1.78 + friend std::basic_istream<CharT,Traits>&
1.79 + operator>>(std::basic_istream<CharT,Traits>& is, cauchy_distribution& cd)
1.80 + {
1.81 + is >> std::ws >> cd._median >> std::ws >> cd._sigma;
1.82 + return is;
1.83 + }
1.84 +#endif
1.85 +
1.86 +private:
1.87 + result_type _median, _sigma;
1.88 +};
1.89 +
1.90 +} // namespace boost
1.91 +
1.92 +#endif // BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP