sl@0: /* boost random/cauchy_distribution.hpp header file sl@0: * sl@0: * Copyright Jens Maurer 2000-2001 sl@0: * Distributed under the Boost Software License, Version 1.0. (See sl@0: * accompanying file LICENSE_1_0.txt or copy at sl@0: * http://www.boost.org/LICENSE_1_0.txt) sl@0: * sl@0: * See http://www.boost.org for most recent version including documentation. sl@0: * sl@0: * $Id: cauchy_distribution.hpp,v 1.15 2004/07/27 03:43:32 dgregor Exp $ sl@0: * sl@0: * Revision history sl@0: * 2001-02-18 moved to individual header files sl@0: */ sl@0: sl@0: #ifndef BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP sl@0: #define BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: namespace boost { sl@0: sl@0: #if defined(__GNUC__) && (__GNUC__ < 3) sl@0: // Special gcc workaround: gcc 2.95.x ignores using-declarations sl@0: // in template classes (confirmed by gcc author Martin v. Loewis) sl@0: using std::tan; sl@0: #endif sl@0: sl@0: // Cauchy distribution: p(x) = sigma/(pi*(sigma**2 + (x-median)**2)) sl@0: template sl@0: class cauchy_distribution sl@0: { sl@0: public: sl@0: typedef RealType input_type; sl@0: typedef RealType result_type; sl@0: sl@0: #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS sl@0: BOOST_STATIC_ASSERT(!std::numeric_limits::is_integer); sl@0: #endif sl@0: sl@0: explicit cauchy_distribution(result_type median = result_type(0), sl@0: result_type sigma = result_type(1)) sl@0: : _median(median), _sigma(sigma) { } sl@0: sl@0: // compiler-generated copy ctor and assignment operator are fine sl@0: sl@0: result_type median() const { return _median; } sl@0: result_type sigma() const { return _sigma; } sl@0: void reset() { } sl@0: sl@0: template sl@0: result_type operator()(Engine& eng) sl@0: { sl@0: // Can we have a boost::mathconst please? sl@0: const result_type pi = result_type(3.14159265358979323846); sl@0: #ifndef BOOST_NO_STDC_NAMESPACE sl@0: using std::tan; sl@0: #endif sl@0: return _median + _sigma * tan(pi*(eng()-result_type(0.5))); sl@0: } sl@0: sl@0: #if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) sl@0: template sl@0: friend std::basic_ostream& sl@0: operator<<(std::basic_ostream& os, const cauchy_distribution& cd) sl@0: { sl@0: os << cd._median << " " << cd._sigma; sl@0: return os; sl@0: } sl@0: sl@0: template sl@0: friend std::basic_istream& sl@0: operator>>(std::basic_istream& is, cauchy_distribution& cd) sl@0: { sl@0: is >> std::ws >> cd._median >> std::ws >> cd._sigma; sl@0: return is; sl@0: } sl@0: #endif sl@0: sl@0: private: sl@0: result_type _median, _sigma; sl@0: }; sl@0: sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP