File indexing completed on 2026-05-03 08:13:38
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___RANDOM_LOGNORMAL_DISTRIBUTION_H
0010 #define _LIBCPP___CXX03___RANDOM_LOGNORMAL_DISTRIBUTION_H
0011
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__random/is_valid.h>
0014 #include <__cxx03/__random/normal_distribution.h>
0015 #include <__cxx03/cmath>
0016 #include <__cxx03/iosfwd>
0017 #include <__cxx03/limits>
0018
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 # pragma GCC system_header
0021 #endif
0022
0023 _LIBCPP_PUSH_MACROS
0024 #include <__cxx03/__undef_macros>
0025
0026 _LIBCPP_BEGIN_NAMESPACE_STD
0027
0028 template <class _RealType = double>
0029 class _LIBCPP_TEMPLATE_VIS lognormal_distribution {
0030 static_assert(__libcpp_random_is_valid_realtype<_RealType>::value,
0031 "RealType must be a supported floating-point type");
0032
0033 public:
0034
0035 typedef _RealType result_type;
0036
0037 class _LIBCPP_TEMPLATE_VIS param_type {
0038 result_type __m_;
0039 result_type __s_;
0040
0041 public:
0042 typedef lognormal_distribution distribution_type;
0043
0044 _LIBCPP_HIDE_FROM_ABI explicit param_type(result_type __m = 0, result_type __s = 1) : __m_(__m), __s_(__s) {}
0045
0046 _LIBCPP_HIDE_FROM_ABI result_type m() const { return __m_; }
0047 _LIBCPP_HIDE_FROM_ABI result_type s() const { return __s_; }
0048
0049 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const param_type& __x, const param_type& __y) {
0050 return __x.__m_ == __y.__m_ && __x.__s_ == __y.__s_;
0051 }
0052 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const param_type& __x, const param_type& __y) { return !(__x == __y); }
0053 };
0054
0055 private:
0056 normal_distribution<result_type> __nd_;
0057
0058 public:
0059
0060 #ifndef _LIBCPP_CXX03_LANG
0061 _LIBCPP_HIDE_FROM_ABI lognormal_distribution() : lognormal_distribution(0) {}
0062 _LIBCPP_HIDE_FROM_ABI explicit lognormal_distribution(result_type __m, result_type __s = 1) : __nd_(__m, __s) {}
0063 #else
0064 _LIBCPP_HIDE_FROM_ABI explicit lognormal_distribution(result_type __m = 0, result_type __s = 1) : __nd_(__m, __s) {}
0065 #endif
0066 _LIBCPP_HIDE_FROM_ABI explicit lognormal_distribution(const param_type& __p) : __nd_(__p.m(), __p.s()) {}
0067 _LIBCPP_HIDE_FROM_ABI void reset() { __nd_.reset(); }
0068
0069
0070 template <class _URNG>
0071 _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g) {
0072 return std::exp(__nd_(__g));
0073 }
0074
0075 template <class _URNG>
0076 _LIBCPP_HIDE_FROM_ABI result_type operator()(_URNG& __g, const param_type& __p) {
0077 typename normal_distribution<result_type>::param_type __pn(__p.m(), __p.s());
0078 return std::exp(__nd_(__g, __pn));
0079 }
0080
0081
0082 _LIBCPP_HIDE_FROM_ABI result_type m() const { return __nd_.mean(); }
0083 _LIBCPP_HIDE_FROM_ABI result_type s() const { return __nd_.stddev(); }
0084
0085 _LIBCPP_HIDE_FROM_ABI param_type param() const { return param_type(__nd_.mean(), __nd_.stddev()); }
0086 _LIBCPP_HIDE_FROM_ABI void param(const param_type& __p) {
0087 typename normal_distribution<result_type>::param_type __pn(__p.m(), __p.s());
0088 __nd_.param(__pn);
0089 }
0090
0091 _LIBCPP_HIDE_FROM_ABI result_type min() const { return 0; }
0092 _LIBCPP_HIDE_FROM_ABI result_type max() const { return numeric_limits<result_type>::infinity(); }
0093
0094 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const lognormal_distribution& __x, const lognormal_distribution& __y) {
0095 return __x.__nd_ == __y.__nd_;
0096 }
0097 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const lognormal_distribution& __x, const lognormal_distribution& __y) {
0098 return !(__x == __y);
0099 }
0100
0101 template <class _CharT, class _Traits, class _RT>
0102 friend basic_ostream<_CharT, _Traits>&
0103 operator<<(basic_ostream<_CharT, _Traits>& __os, const lognormal_distribution<_RT>& __x);
0104
0105 template <class _CharT, class _Traits, class _RT>
0106 friend basic_istream<_CharT, _Traits>&
0107 operator>>(basic_istream<_CharT, _Traits>& __is, lognormal_distribution<_RT>& __x);
0108 };
0109
0110 template <class _CharT, class _Traits, class _RT>
0111 inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0112 operator<<(basic_ostream<_CharT, _Traits>& __os, const lognormal_distribution<_RT>& __x) {
0113 return __os << __x.__nd_;
0114 }
0115
0116 template <class _CharT, class _Traits, class _RT>
0117 inline _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
0118 operator>>(basic_istream<_CharT, _Traits>& __is, lognormal_distribution<_RT>& __x) {
0119 return __is >> __x.__nd_;
0120 }
0121
0122 _LIBCPP_END_NAMESPACE_STD
0123
0124 _LIBCPP_POP_MACROS
0125
0126 #endif