1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H
10 #define _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H
13 #include <__random/normal_distribution.h>
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 # pragma GCC system_header
23 #include <__undef_macros>
25 _LIBCPP_BEGIN_NAMESPACE_STD
27 template<class _RealType
= double>
28 class _LIBCPP_TEMPLATE_VIS lognormal_distribution
32 typedef _RealType result_type
;
34 class _LIBCPP_TEMPLATE_VIS param_type
39 typedef lognormal_distribution distribution_type
;
41 _LIBCPP_INLINE_VISIBILITY
42 explicit param_type(result_type __m
= 0, result_type __s
= 1)
43 : __m_(__m
), __s_(__s
) {}
45 _LIBCPP_INLINE_VISIBILITY
46 result_type
m() const {return __m_
;}
47 _LIBCPP_INLINE_VISIBILITY
48 result_type
s() const {return __s_
;}
50 friend _LIBCPP_INLINE_VISIBILITY
51 bool operator==(const param_type
& __x
, const param_type
& __y
)
52 {return __x
.__m_
== __y
.__m_
&& __x
.__s_
== __y
.__s_
;}
53 friend _LIBCPP_INLINE_VISIBILITY
54 bool operator!=(const param_type
& __x
, const param_type
& __y
)
55 {return !(__x
== __y
);}
59 normal_distribution
<result_type
> __nd_
;
62 // constructor and reset functions
63 #ifndef _LIBCPP_CXX03_LANG
64 _LIBCPP_INLINE_VISIBILITY
65 lognormal_distribution() : lognormal_distribution(0) {}
66 _LIBCPP_INLINE_VISIBILITY
67 explicit lognormal_distribution(result_type __m
, result_type __s
= 1)
70 _LIBCPP_INLINE_VISIBILITY
71 explicit lognormal_distribution(result_type __m
= 0,
75 _LIBCPP_INLINE_VISIBILITY
76 explicit lognormal_distribution(const param_type
& __p
)
77 : __nd_(__p
.m(), __p
.s()) {}
78 _LIBCPP_INLINE_VISIBILITY
79 void reset() {__nd_
.reset();}
81 // generating functions
83 _LIBCPP_INLINE_VISIBILITY
84 result_type
operator()(_URNG
& __g
)
86 return _VSTD::exp(__nd_(__g
));
90 _LIBCPP_INLINE_VISIBILITY
91 result_type
operator()(_URNG
& __g
, const param_type
& __p
)
93 typename normal_distribution
<result_type
>::param_type
__pn(__p
.m(), __p
.s());
94 return _VSTD::exp(__nd_(__g
, __pn
));
98 _LIBCPP_INLINE_VISIBILITY
99 result_type
m() const {return __nd_
.mean();}
100 _LIBCPP_INLINE_VISIBILITY
101 result_type
s() const {return __nd_
.stddev();}
103 _LIBCPP_INLINE_VISIBILITY
104 param_type
param() const {return param_type(__nd_
.mean(), __nd_
.stddev());}
105 _LIBCPP_INLINE_VISIBILITY
106 void param(const param_type
& __p
)
108 typename normal_distribution
<result_type
>::param_type
__pn(__p
.m(), __p
.s());
112 _LIBCPP_INLINE_VISIBILITY
113 result_type
min() const {return 0;}
114 _LIBCPP_INLINE_VISIBILITY
115 result_type
max() const {return numeric_limits
<result_type
>::infinity();}
117 friend _LIBCPP_INLINE_VISIBILITY
118 bool operator==(const lognormal_distribution
& __x
,
119 const lognormal_distribution
& __y
)
120 {return __x
.__nd_
== __y
.__nd_
;}
121 friend _LIBCPP_INLINE_VISIBILITY
122 bool operator!=(const lognormal_distribution
& __x
,
123 const lognormal_distribution
& __y
)
124 {return !(__x
== __y
);}
126 template <class _CharT
, class _Traits
, class _RT
>
128 basic_ostream
<_CharT
, _Traits
>&
129 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
,
130 const lognormal_distribution
<_RT
>& __x
);
132 template <class _CharT
, class _Traits
, class _RT
>
134 basic_istream
<_CharT
, _Traits
>&
135 operator>>(basic_istream
<_CharT
, _Traits
>& __is
,
136 lognormal_distribution
<_RT
>& __x
);
139 template <class _CharT
, class _Traits
, class _RT
>
140 inline _LIBCPP_INLINE_VISIBILITY
141 basic_ostream
<_CharT
, _Traits
>&
142 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
,
143 const lognormal_distribution
<_RT
>& __x
)
145 return __os
<< __x
.__nd_
;
148 template <class _CharT
, class _Traits
, class _RT
>
149 inline _LIBCPP_INLINE_VISIBILITY
150 basic_istream
<_CharT
, _Traits
>&
151 operator>>(basic_istream
<_CharT
, _Traits
>& __is
,
152 lognormal_distribution
<_RT
>& __x
)
154 return __is
>> __x
.__nd_
;
157 _LIBCPP_END_NAMESPACE_STD
161 #endif // _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H