]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/random/cauchy_distribution.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
338821276e48b13d81d7defb63c6faee9e49ff2c
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / random / cauchy_distribution.hpp
1 /* boost random/cauchy_distribution.hpp header file\r
2  *\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
7  *\r
8  * See http://www.boost.org for most recent version including documentation.\r
9  *\r
10  * $Id: cauchy_distribution.hpp 52492 2009-04-19 14:55:57Z steven_watanabe $\r
11  *\r
12  * Revision history\r
13  *  2001-02-18  moved to individual header files\r
14  */\r
15 \r
16 #ifndef BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP\r
17 #define BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP\r
18 \r
19 #include <boost/config/no_tr1/cmath.hpp>\r
20 #include <iostream>\r
21 #include <boost/limits.hpp>\r
22 #include <boost/static_assert.hpp>\r
23 #include <boost/random/detail/config.hpp>\r
24 \r
25 namespace boost {\r
26 \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
30   using std::tan;\r
31 #endif\r
32 \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
36 {\r
37 public:\r
38   typedef RealType input_type;\r
39   typedef RealType result_type;\r
40 \r
41 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS\r
42   BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);\r
43 #endif\r
44 \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
48 \r
49   // compiler-generated copy ctor and assignment operator are fine\r
50 \r
51   result_type median() const { return _median; }\r
52   result_type sigma() const { return _sigma; }\r
53   void reset() { }\r
54 \r
55   template<class Engine>\r
56   result_type operator()(Engine& eng)\r
57   {\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
61     using std::tan;\r
62 #endif\r
63     return _median + _sigma * tan(pi*(eng()-result_type(0.5)));\r
64   }\r
65 \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
70   {\r
71     os << cd._median << " " << cd._sigma;\r
72     return os;\r
73   }\r
74 \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
78   {\r
79     is >> std::ws >> cd._median >> std::ws >> cd._sigma;\r
80     return is;\r
81   }\r
82 #endif\r
83 \r
84 private:\r
85   result_type _median, _sigma;\r
86 };\r
87 \r
88 } // namespace boost\r
89 \r
90 #endif // BOOST_RANDOM_CAUCHY_DISTRIBUTION_HPP\r