1 /* boost random/cauchy_distribution.hpp header file
\r
3 * Copyright Jens Maurer 2000-2001
\r
4 * Distributed under the Boost Software License, Version 1.0. (See
\r
5 * accompanying file LICENSE_1_0.txt or copy at
\r
6 * http://www.boost.org/LICENSE_1_0.txt)
\r
8 * See http://www.boost.org for most recent version including documentation.
\r
10 * $Id: cauchy_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $
\r
13 * 2001-02-18 moved to individual header files
\r
16 #ifndef BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP
\r
17 #define BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP
\r
19 #include <boost/config/no_tr1/cmath.hpp>
\r
21 #include <boost/limits.hpp>
\r
22 #include <boost/static_assert.hpp>
\r
23 #include <boost/random/detail/config.hpp>
\r
27 #if defined(__GNUC__) && (__GNUC__ < 3)
\r
28 // Special gcc workaround: gcc 2.95.x ignores using-declarations
\r
29 // in template classes (confirmed by gcc author Martin v. Loewis)
\r
33 // Cauchy distribution: p(x) = sigma/(pi*(sigma**2 + (x-median)**2))
\r
34 template<class RealType = double>
\r
35 class cauchy_distribution
\r
38 typedef RealType input_type;
\r
39 typedef RealType result_type;
\r
41 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
\r
42 BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
\r
45 explicit cauchy_distribution(result_type median_arg = result_type(0),
\r
46 result_type sigma_arg = result_type(1))
\r
47 : _median(median_arg), _sigma(sigma_arg) { }
\r
49 // compiler-generated copy ctor and assignment operator are fine
\r
51 result_type median() const { return _median; }
\r
52 result_type sigma() const { return _sigma; }
\r
55 template<class Engine>
\r
56 result_type operator()(Engine& eng)
\r
58 // Can we have a boost::mathconst please?
\r
59 const result_type pi = result_type(3.14159265358979323846);
\r
60 #ifndef BOOST_NO_STDC_NAMESPACE
\r
63 return _median + _sigma * tan(pi*(eng()-result_type(0.5)));
\r
66 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
\r
67 template<class CharT, class Traits>
\r
68 friend std::basic_ostream<CharT,Traits>&
\r
69 operator<<(std::basic_ostream<CharT,Traits>& os, const cauchy_distribution& cd)
\r
71 os << cd._median << " " << cd._sigma;
\r
75 template<class CharT, class Traits>
\r
76 friend std::basic_istream<CharT,Traits>&
\r
77 operator>>(std::basic_istream<CharT,Traits>& is, cauchy_distribution& cd)
\r
79 is >> std::ws >> cd._median >> std::ws >> cd._sigma;
\r
85 result_type _median, _sigma;
\r
88 } // namespace boost
\r
90 #endif // BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP
\r