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