35namespace std _GLIBCXX_VISIBILITY(default)
37_GLIBCXX_BEGIN_NAMESPACE_VERSION
49 template<
typename _Tp, _Tp __m, _Tp __a, _Tp __c>
51 _Mod<_Tp, __m, __a, __c, false, true>::
58 static const _Tp __q = __m / __a;
59 static const _Tp __r = __m % __a;
61 _Tp __t1 = __a * (__x % __q);
62 _Tp __t2 = __r * (__x / __q);
66 __x = __m - __t2 + __t1;
71 const _Tp __d = __m - __x;
80 template<
typename _InputIterator,
typename _OutputIterator,
83 __normalize(_InputIterator __first, _InputIterator __last,
84 _OutputIterator __result,
const _Tp& __factor)
86 for (; __first != __last; ++__first, ++__result)
87 *__result = *__first / __factor;
94#if ! __cpp_inline_variables
95 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
99 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
103 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
107 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
109 linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed;
116 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
121 if ((__detail::__mod<_UIntType, __m>(__c) == 0)
122 && (__detail::__mod<_UIntType, __m>(__s) == 0))
125 _M_x = __detail::__mod<_UIntType, __m>(__s);
131 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
132 template<
typename _Sseq>
136 -> _If_seed_seq<_Sseq>
140 const _UIntType __k = (__k0 + 31) / 32;
141 uint_least32_t __arr[__k + 3];
142 __q.generate(__arr + 0, __arr + __k + 3);
143 _UIntType __factor = 1u;
144 _UIntType __sum = 0u;
145 for (
size_t __j = 0; __j < __k; ++__j)
147 __sum += __arr[__j + 3] * __factor;
148 __factor *= __detail::_Shift<_UIntType, 32>::__value;
153 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
154 typename _CharT,
typename _Traits>
158 __a, __c, __m>& __lcr)
160 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
162 const typename __ios_base::fmtflags __flags = __os.
flags();
163 const _CharT __fill = __os.
fill();
164 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
174 template<
typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m,
175 typename _CharT,
typename _Traits>
178 linear_congruential_engine<_UIntType, __a, __c, __m>& __lcr)
180 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
182 const typename __ios_base::fmtflags __flags = __is.
flags();
183 __is.
flags(__ios_base::dec);
191#if ! __cpp_inline_variables
192 template<
typename _UIntType,
193 size_t __w,
size_t __n,
size_t __m,
size_t __r,
194 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
195 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
199 __s, __b, __t, __c, __l, __f>::word_size;
201 template<
typename _UIntType,
202 size_t __w,
size_t __n,
size_t __m,
size_t __r,
203 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
204 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
208 __s, __b, __t, __c, __l, __f>::state_size;
210 template<
typename _UIntType,
211 size_t __w,
size_t __n,
size_t __m,
size_t __r,
212 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
213 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
217 __s, __b, __t, __c, __l, __f>::shift_size;
219 template<
typename _UIntType,
220 size_t __w,
size_t __n,
size_t __m,
size_t __r,
221 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
222 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
226 __s, __b, __t, __c, __l, __f>::mask_bits;
228 template<
typename _UIntType,
229 size_t __w,
size_t __n,
size_t __m,
size_t __r,
230 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
231 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
235 __s, __b, __t, __c, __l, __f>::xor_mask;
237 template<
typename _UIntType,
238 size_t __w,
size_t __n,
size_t __m,
size_t __r,
239 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
240 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
244 __s, __b, __t, __c, __l, __f>::tempering_u;
246 template<
typename _UIntType,
247 size_t __w,
size_t __n,
size_t __m,
size_t __r,
248 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
249 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
253 __s, __b, __t, __c, __l, __f>::tempering_d;
255 template<
typename _UIntType,
256 size_t __w,
size_t __n,
size_t __m,
size_t __r,
257 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
258 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
262 __s, __b, __t, __c, __l, __f>::tempering_s;
264 template<
typename _UIntType,
265 size_t __w,
size_t __n,
size_t __m,
size_t __r,
266 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
267 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
271 __s, __b, __t, __c, __l, __f>::tempering_b;
273 template<
typename _UIntType,
274 size_t __w,
size_t __n,
size_t __m,
size_t __r,
275 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
276 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
280 __s, __b, __t, __c, __l, __f>::tempering_t;
282 template<
typename _UIntType,
283 size_t __w,
size_t __n,
size_t __m,
size_t __r,
284 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
285 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
289 __s, __b, __t, __c, __l, __f>::tempering_c;
291 template<
typename _UIntType,
292 size_t __w,
size_t __n,
size_t __m,
size_t __r,
293 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
294 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
298 __s, __b, __t, __c, __l, __f>::tempering_l;
300 template<
typename _UIntType,
301 size_t __w,
size_t __n,
size_t __m,
size_t __r,
302 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
303 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
307 __s, __b, __t, __c, __l, __f>::
308 initialization_multiplier;
310 template<
typename _UIntType,
311 size_t __w,
size_t __n,
size_t __m,
size_t __r,
312 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
313 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
317 __s, __b, __t, __c, __l, __f>::default_seed;
320 template<
typename _UIntType,
321 size_t __w,
size_t __n,
size_t __m,
size_t __r,
322 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
323 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
327 __s, __b, __t, __c, __l, __f>::
328 seed(result_type __sd)
330 _M_x[0] = __detail::__mod<_UIntType,
331 __detail::_Shift<_UIntType, __w>::__value>(__sd);
333 for (
size_t __i = 1; __i < state_size; ++__i)
335 _UIntType __x = _M_x[__i - 1];
336 __x ^= __x >> (__w - 2);
338 __x += __detail::__mod<_UIntType, __n>(__i);
339 _M_x[__i] = __detail::__mod<_UIntType,
340 __detail::_Shift<_UIntType, __w>::__value>(__x);
345 template<
typename _UIntType,
346 size_t __w,
size_t __n,
size_t __m,
size_t __r,
347 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
348 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
350 template<
typename _Sseq>
353 __s, __b, __t, __c, __l, __f>::
355 -> _If_seed_seq<_Sseq>
357 const _UIntType __upper_mask = (~_UIntType()) << __r;
358 const size_t __k = (__w + 31) / 32;
359 uint_least32_t __arr[__n * __k];
360 __q.generate(__arr + 0, __arr + __n * __k);
363 for (
size_t __i = 0; __i < state_size; ++__i)
365 _UIntType __factor = 1u;
366 _UIntType __sum = 0u;
367 for (
size_t __j = 0; __j < __k; ++__j)
369 __sum += __arr[__k * __i + __j] * __factor;
370 __factor *= __detail::_Shift<_UIntType, 32>::__value;
372 _M_x[__i] = __detail::__mod<_UIntType,
373 __detail::_Shift<_UIntType, __w>::__value>(__sum);
379 if ((_M_x[0] & __upper_mask) != 0u)
382 else if (_M_x[__i] != 0u)
387 _M_x[0] = __detail::_Shift<_UIntType, __w - 1>::__value;
391 template<
typename _UIntType,
size_t __w,
392 size_t __n,
size_t __m,
size_t __r,
393 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
394 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
398 __s, __b, __t, __c, __l, __f>::
401 const _UIntType __upper_mask = (~_UIntType()) << __r;
402 const _UIntType __lower_mask = ~__upper_mask;
404 for (
size_t __k = 0; __k < (__n - __m); ++__k)
406 _UIntType __y = ((_M_x[__k] & __upper_mask)
407 | (_M_x[__k + 1] & __lower_mask));
408 _M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
409 ^ ((__y & 0x01) ? __a : 0));
412 for (
size_t __k = (__n - __m); __k < (__n - 1); ++__k)
414 _UIntType __y = ((_M_x[__k] & __upper_mask)
415 | (_M_x[__k + 1] & __lower_mask));
416 _M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
417 ^ ((__y & 0x01) ? __a : 0));
420 _UIntType __y = ((_M_x[__n - 1] & __upper_mask)
421 | (_M_x[0] & __lower_mask));
422 _M_x[__n - 1] = (_M_x[__m - 1] ^ (__y >> 1)
423 ^ ((__y & 0x01) ? __a : 0));
427 template<
typename _UIntType,
size_t __w,
428 size_t __n,
size_t __m,
size_t __r,
429 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
430 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
434 __s, __b, __t, __c, __l, __f>::
435 discard(
unsigned long long __z)
437 while (__z > state_size - _M_p)
439 __z -= state_size - _M_p;
445 template<
typename _UIntType,
size_t __w,
446 size_t __n,
size_t __m,
size_t __r,
447 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
448 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
452 __s, __b, __t, __c, __l, __f>::result_type
454 __s, __b, __t, __c, __l, __f>::
458 if (_M_p >= state_size)
462 result_type __z = _M_x[_M_p++];
463 __z ^= (__z >> __u) & __d;
464 __z ^= (__z << __s) & __b;
465 __z ^= (__z << __t) & __c;
471 template<
typename _UIntType,
size_t __w,
472 size_t __n,
size_t __m,
size_t __r,
473 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
474 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
475 _UIntType __f,
typename _CharT,
typename _Traits>
478 const mersenne_twister_engine<_UIntType, __w, __n, __m,
479 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
481 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
483 const typename __ios_base::fmtflags __flags = __os.
flags();
484 const _CharT __fill = __os.
fill();
485 const _CharT __space = __os.
widen(
' ');
486 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
489 for (
size_t __i = 0; __i < __n; ++__i)
490 __os << __x._M_x[__i] << __space;
498 template<
typename _UIntType,
size_t __w,
499 size_t __n,
size_t __m,
size_t __r,
500 _UIntType __a,
size_t __u, _UIntType __d,
size_t __s,
501 _UIntType __b,
size_t __t, _UIntType __c,
size_t __l,
502 _UIntType __f,
typename _CharT,
typename _Traits>
503 std::basic_istream<_CharT, _Traits>&
504 operator>>(std::basic_istream<_CharT, _Traits>& __is,
506 __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>& __x)
508 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
510 const typename __ios_base::fmtflags __flags = __is.
flags();
511 __is.
flags(__ios_base::dec | __ios_base::skipws);
513 for (
size_t __i = 0; __i < __n; ++__i)
514 __is >> __x._M_x[__i];
521#if ! __cpp_inline_variables
522 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
524 subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size;
526 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
528 subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag;
530 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
532 subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag;
534 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
535 constexpr uint_least32_t
536 subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed;
539 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
548 __lcg(__value == 0u ? default_seed : __value % 2147483563u);
550 const size_t __n = (__w + 31) / 32;
552 for (
size_t __i = 0; __i < long_lag; ++__i)
554 _UIntType __sum = 0u;
555 _UIntType __factor = 1u;
556 for (
size_t __j = 0; __j < __n; ++__j)
558 __sum += __detail::__mod<uint_least32_t,
559 __detail::_Shift<uint_least32_t, 32>::__value>
560 (__lcg()) * __factor;
561 __factor *= __detail::_Shift<_UIntType, 32>::__value;
563 _M_x[__i] = __detail::__mod<_UIntType,
564 __detail::_Shift<_UIntType, __w>::__value>(__sum);
566 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
570 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
571 template<
typename _Sseq>
575 -> _If_seed_seq<_Sseq>
577 const size_t __k = (__w + 31) / 32;
578 uint_least32_t __arr[__r * __k];
579 __q.generate(__arr + 0, __arr + __r * __k);
581 for (
size_t __i = 0; __i < long_lag; ++__i)
583 _UIntType __sum = 0u;
584 _UIntType __factor = 1u;
585 for (
size_t __j = 0; __j < __k; ++__j)
587 __sum += __arr[__k * __i + __j] * __factor;
588 __factor *= __detail::_Shift<_UIntType, 32>::__value;
590 _M_x[__i] = __detail::__mod<_UIntType,
591 __detail::_Shift<_UIntType, __w>::__value>(__sum);
593 _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
597 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r>
604 long __ps = _M_p - short_lag;
612 if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
614 __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
619 __xi = (__detail::_Shift<_UIntType, __w>::__value
620 - _M_x[_M_p] - _M_carry + _M_x[__ps]);
626 if (++_M_p >= long_lag)
632 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
633 typename _CharT,
typename _Traits>
639 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
641 const typename __ios_base::fmtflags __flags = __os.
flags();
642 const _CharT __fill = __os.
fill();
643 const _CharT __space = __os.
widen(
' ');
644 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
647 for (
size_t __i = 0; __i < __r; ++__i)
648 __os << __x._M_x[__i] << __space;
649 __os << __x._M_carry << __space << __x._M_p;
656 template<
typename _UIntType,
size_t __w,
size_t __s,
size_t __r,
657 typename _CharT,
typename _Traits>
660 subtract_with_carry_engine<_UIntType, __w, __s, __r>& __x)
662 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
664 const typename __ios_base::fmtflags __flags = __is.
flags();
665 __is.
flags(__ios_base::dec | __ios_base::skipws);
667 for (
size_t __i = 0; __i < __r; ++__i)
668 __is >> __x._M_x[__i];
669 __is >> __x._M_carry;
676#if ! __cpp_inline_variables
677 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
679 discard_block_engine<_RandomNumberEngine, __p, __r>::block_size;
681 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
683 discard_block_engine<_RandomNumberEngine, __p, __r>::used_block;
686 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r>
692 if (_M_n >= used_block)
694 _M_b.discard(block_size - _M_n);
701 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
702 typename _CharT,
typename _Traits>
708 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
710 const typename __ios_base::fmtflags __flags = __os.
flags();
711 const _CharT __fill = __os.
fill();
712 const _CharT __space = __os.
widen(
' ');
713 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
716 __os << __x.base() << __space << __x._M_n;
723 template<
typename _RandomNumberEngine,
size_t __p,
size_t __r,
724 typename _CharT,
typename _Traits>
727 discard_block_engine<_RandomNumberEngine, __p, __r>& __x)
729 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
731 const typename __ios_base::fmtflags __flags = __is.
flags();
732 __is.
flags(__ios_base::dec | __ios_base::skipws);
734 __is >> __x._M_b >> __x._M_n;
741 template<
typename _RandomNumberEngine,
size_t __w,
typename _UIntType>
747 typedef typename _RandomNumberEngine::result_type _Eresult_type;
748 const _Eresult_type __r
750 ? _M_b.max() - _M_b.min() + 1 : 0);
752 const unsigned __m = __r ?
std::__lg(__r) : __edig;
759 __ctype __s0, __s1, __y0, __y1;
761 for (
size_t __i = 0; __i < 2; ++__i)
763 __n = (__w + __m - 1) / __m + __i;
764 __n0 = __n - __w % __n;
765 const unsigned __w0 = __w / __n;
771 __s0 = __ctype(1) << __w0;
779 __y0 = __s0 * (__r / __s0);
781 __y1 = __s1 * (__r / __s1);
783 if (__r - __y0 <= __y0 / __n)
791 for (
size_t __k = 0; __k < __n0; ++__k)
795 __u = _M_b() - _M_b.min();
796 while (__y0 && __u >= __y0);
797 __sum = __s0 * __sum + (__s0 ? __u % __s0 : __u);
799 for (
size_t __k = __n0; __k < __n; ++__k)
803 __u = _M_b() - _M_b.min();
804 while (__y1 && __u >= __y1);
805 __sum = __s1 * __sum + (__s1 ? __u % __s1 : __u);
810#if ! __cpp_inline_variables
811 template<
typename _RandomNumberEngine,
size_t __k>
813 shuffle_order_engine<_RandomNumberEngine, __k>::table_size;
819 template<
typename _Tp>
821 __representable_as_double(_Tp __x)
noexcept
826 return (__x <= (1ull << __DBL_MANT_DIG__))
828 || (!(__x & 1) && __detail::__representable_as_double(__x >> 1));
832 template<
typename _Tp>
834 __p1_representable_as_double(_Tp __x)
noexcept
840 && __detail::__representable_as_double(__x + 1u));
844 template<
typename _RandomNumberEngine,
size_t __k>
852#pragma GCC diagnostic push
853#pragma GCC diagnostic ignored "-Wc++17-extensions"
855 if constexpr (__detail::__p1_representable_as_double(__range))
856 __j *= __y / (__range + 1.0);
858 __j *= __y / (__range + 1.0L);
859#pragma GCC diagnostic pop
866 template<
typename _RandomNumberEngine,
size_t __k,
867 typename _CharT,
typename _Traits>
872 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
874 const typename __ios_base::fmtflags __flags = __os.
flags();
875 const _CharT __fill = __os.
fill();
876 const _CharT __space = __os.
widen(
' ');
877 __os.
flags(__ios_base::dec | __ios_base::fixed | __ios_base::left);
881 for (
size_t __i = 0; __i < __k; ++__i)
882 __os << __space << __x._M_v[__i];
883 __os << __space << __x._M_y;
890 template<
typename _RandomNumberEngine,
size_t __k,
891 typename _CharT,
typename _Traits>
896 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
898 const typename __ios_base::fmtflags __flags = __is.
flags();
899 __is.
flags(__ios_base::dec | __ios_base::skipws);
902 for (
size_t __i = 0; __i < __k; ++__i)
903 __is >> __x._M_v[__i];
911 template<
typename _IntType,
typename _CharT,
typename _Traits>
916 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
918 const typename __ios_base::fmtflags __flags = __os.
flags();
919 const _CharT __fill = __os.
fill();
920 const _CharT __space = __os.
widen(
' ');
921 __os.
flags(__ios_base::scientific | __ios_base::left);
924 __os << __x.a() << __space << __x.b();
931 template<
typename _IntType,
typename _CharT,
typename _Traits>
938 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
940 const typename __ios_base::fmtflags __flags = __is.
flags();
941 __is.
flags(__ios_base::dec | __ios_base::skipws);
944 if (__is >> __a >> __b)
945 __x.
param(param_type(__a, __b));
952 template<
typename _RealType>
953 template<
typename _ForwardIterator,
954 typename _UniformRandomNumberGenerator>
958 _UniformRandomNumberGenerator& __urng,
959 const param_type& __p)
961 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
962 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
964 auto __range = __p.b() - __p.a();
966 *__f++ = __aurng() * __range + __p.a();
969 template<
typename _RealType,
typename _CharT,
typename _Traits>
972 const uniform_real_distribution<_RealType>& __x)
974 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
976 const typename __ios_base::fmtflags __flags = __os.
flags();
977 const _CharT __fill = __os.
fill();
979 const _CharT __space = __os.
widen(
' ');
980 __os.
flags(__ios_base::scientific | __ios_base::left);
984 __os << __x.a() << __space << __x.b();
992 template<
typename _RealType,
typename _CharT,
typename _Traits>
993 std::basic_istream<_CharT, _Traits>&
999 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1001 const typename __ios_base::fmtflags __flags = __is.
flags();
1002 __is.
flags(__ios_base::skipws);
1005 if (__is >> __a >> __b)
1006 __x.
param(param_type(__a, __b));
1008 __is.
flags(__flags);
1013 template<
typename _ForwardIterator,
1014 typename _UniformRandomNumberGenerator>
1016 std::bernoulli_distribution::
1017 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1018 _UniformRandomNumberGenerator& __urng,
1019 const param_type& __p)
1021 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1022 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1024 auto __limit = __p.p() * (__aurng.max() - __aurng.min());
1027 *__f++ = (__aurng() - __aurng.min()) < __limit;
1030 template<
typename _CharT,
typename _Traits>
1033 const bernoulli_distribution& __x)
1035 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1037 const typename __ios_base::fmtflags __flags = __os.
flags();
1038 const _CharT __fill = __os.
fill();
1040 __os.
flags(__ios_base::scientific | __ios_base::left);
1046 __os.
flags(__flags);
1053 template<
typename _IntType>
1054 template<
typename _UniformRandomNumberGenerator>
1057 operator()(_UniformRandomNumberGenerator& __urng,
1058 const param_type& __param)
1062 const double __naf =
1065 const double __thr =
1067 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1072 __cand = std::floor(
std::log(1.0 - __aurng()) / __param._M_log_1_p);
1073 while (__cand >= __thr);
1075 return result_type(__cand + __naf);
1078 template<
typename _IntType>
1079 template<
typename _ForwardIterator,
1080 typename _UniformRandomNumberGenerator>
1084 _UniformRandomNumberGenerator& __urng,
1085 const param_type& __param)
1087 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1090 const double __naf =
1093 const double __thr =
1095 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1102 __cand = std::floor(
std::log(1.0 - __aurng())
1103 / __param._M_log_1_p);
1104 while (__cand >= __thr);
1106 *__f++ = __cand + __naf;
1110 template<
typename _IntType,
1111 typename _CharT,
typename _Traits>
1114 const geometric_distribution<_IntType>& __x)
1116 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1118 const typename __ios_base::fmtflags __flags = __os.
flags();
1119 const _CharT __fill = __os.
fill();
1121 __os.
flags(__ios_base::scientific | __ios_base::left);
1127 __os.
flags(__flags);
1133 template<
typename _IntType,
1134 typename _CharT,
typename _Traits>
1135 std::basic_istream<_CharT, _Traits>&
1140 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1142 const typename __ios_base::fmtflags __flags = __is.
flags();
1143 __is.
flags(__ios_base::skipws);
1149 __is.
flags(__flags);
1154 template<
typename _IntType>
1155 template<
typename _UniformRandomNumberGenerator>
1158 operator()(_UniformRandomNumberGenerator& __urng)
1160 const double __y = _M_gd(__urng);
1164 return __poisson(__urng);
1167 template<
typename _IntType>
1168 template<
typename _UniformRandomNumberGenerator>
1171 operator()(_UniformRandomNumberGenerator& __urng,
1172 const param_type& __p)
1178 _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
1181 return __poisson(__urng);
1184 template<
typename _IntType>
1185 template<
typename _ForwardIterator,
1186 typename _UniformRandomNumberGenerator>
1188 negative_binomial_distribution<_IntType>::
1189 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1190 _UniformRandomNumberGenerator& __urng)
1192 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1195 const double __y = _M_gd(__urng);
1199 *__f++ = __poisson(__urng);
1203 template<
typename _IntType>
1204 template<
typename _ForwardIterator,
1205 typename _UniformRandomNumberGenerator>
1209 _UniformRandomNumberGenerator& __urng,
1210 const param_type& __p)
1212 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1213 typename std::gamma_distribution<result_type>::param_type
1214 __p2(__p.k(), (1.0 - __p.p()) / __p.p());
1218 const double __y = _M_gd(__urng, __p2);
1220 std::poisson_distribution<result_type> __poisson(__y);
1221 *__f++ = __poisson(__urng);
1225 template<
typename _IntType,
typename _CharT,
typename _Traits>
1226 std::basic_ostream<_CharT, _Traits>&
1227 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1230 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1232 const typename __ios_base::fmtflags __flags = __os.
flags();
1233 const _CharT __fill = __os.
fill();
1235 const _CharT __space = __os.
widen(
' ');
1236 __os.
flags(__ios_base::scientific | __ios_base::left);
1238 __os.
precision(std::numeric_limits<double>::max_digits10);
1240 __os << __x.k() << __space << __x.p()
1241 << __space << __x._M_gd;
1243 __os.
flags(__flags);
1249 template<
typename _IntType,
typename _CharT,
typename _Traits>
1250 std::basic_istream<_CharT, _Traits>&
1251 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1256 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1258 const typename __ios_base::fmtflags __flags = __is.
flags();
1259 __is.
flags(__ios_base::skipws);
1263 if (__is >> __k >> __p >> __x._M_gd)
1264 __x.param(param_type(__k, __p));
1266 __is.
flags(__flags);
1271 template<
typename _IntType>
1276#if _GLIBCXX_USE_C99_MATH_FUNCS
1279 const double __m = std::floor(_M_mean);
1281 _M_lfm = std::lgamma(__m + 1);
1284 const double __pi_4 = 0.7853981633974483096156608458198757L;
1288 const double __cx = 2 * __m + _M_d;
1293 _M_cb = 2 * __cx *
std::exp(-_M_d * _M_1cx * (1 + _M_d / 2))
1311 template<
typename _IntType>
1312 template<
typename _UniformRandomNumberGenerator>
1313 typename poisson_distribution<_IntType>::result_type
1315 operator()(_UniformRandomNumberGenerator& __urng,
1318 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1320#if _GLIBCXX_USE_C99_MATH_FUNCS
1321 if (__param.mean() >= 12)
1326 const double __naf =
1328 const double __thr =
1331 const double __m = std::floor(__param.mean());
1333 const double __spi_2 = 1.2533141373155002512078826424055226L;
1334 const double __c1 = __param._M_sm * __spi_2;
1335 const double __c2 = __param._M_c2b + __c1;
1336 const double __c3 = __c2 + 1;
1337 const double __c4 = __c3 + 1;
1339 const double __178 = 0.0128205128205128205128205128205128L;
1341 const double __e178 = 1.0129030479320018583185514777512983L;
1342 const double __c5 = __c4 + __e178;
1343 const double __c = __param._M_cb + __c5;
1344 const double __2cx = 2 * (2 * __m + __param._M_d);
1346 bool __reject =
true;
1349 const double __u = __c * __aurng();
1350 const double __e = -
std::log(1.0 - __aurng());
1356 const double __n = _M_nd(__urng);
1357 const double __y = -
std::abs(__n) * __param._M_sm - 1;
1358 __x = std::floor(__y);
1359 __w = -__n * __n / 2;
1363 else if (__u <= __c2)
1365 const double __n = _M_nd(__urng);
1366 const double __y = 1 +
std::abs(__n) * __param._M_scx;
1367 __x = std::ceil(__y);
1368 __w = __y * (2 - __y) * __param._M_1cx;
1369 if (__x > __param._M_d)
1372 else if (__u <= __c3)
1376 else if (__u <= __c4)
1378 else if (__u <= __c5)
1386 const double __v = -
std::log(1.0 - __aurng());
1387 const double __y = __param._M_d
1388 + __v * __2cx / __param._M_d;
1389 __x = std::ceil(__y);
1390 __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
1393 __reject = (__w - __e - __x * __param._M_lm_thr
1394 > __param._M_lfm - std::lgamma(__x + __m + 1));
1396 __reject |= __x + __m >= __thr;
1406 double __prod = 1.0;
1410 __prod *= __aurng();
1413 while (__prod > __param._M_lm_thr);
1419 template<
typename _IntType>
1420 template<
typename _ForwardIterator,
1421 typename _UniformRandomNumberGenerator>
1425 _UniformRandomNumberGenerator& __urng,
1426 const param_type& __param)
1428 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1434 template<
typename _IntType,
1435 typename _CharT,
typename _Traits>
1438 const poisson_distribution<_IntType>& __x)
1440 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1442 const typename __ios_base::fmtflags __flags = __os.
flags();
1443 const _CharT __fill = __os.
fill();
1445 const _CharT __space = __os.
widen(
' ');
1446 __os.
flags(__ios_base::scientific | __ios_base::left);
1450 __os << __x.mean() << __space << __x._M_nd;
1452 __os.
flags(__flags);
1458 template<
typename _IntType,
1459 typename _CharT,
typename _Traits>
1460 std::basic_istream<_CharT, _Traits>&
1461 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1462 poisson_distribution<_IntType>& __x)
1464 using param_type =
typename poisson_distribution<_IntType>::param_type;
1465 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1467 const typename __ios_base::fmtflags __flags = __is.
flags();
1468 __is.
flags(__ios_base::skipws);
1471 if (__is >> __mean >> __x._M_nd)
1474 __is.
flags(__flags);
1479 template<
typename _IntType>
1481 binomial_distribution<_IntType>::param_type::
1484 const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
1488#if _GLIBCXX_USE_C99_MATH_FUNCS
1489 if (_M_t * __p12 >= 8)
1492 const double __np = std::floor(_M_t * __p12);
1493 const double __pa = __np / _M_t;
1494 const double __1p = 1 - __pa;
1496 const double __pi_4 = 0.7853981633974483096156608458198757L;
1497 const double __d1x =
1499 / (81 * __pi_4 * __1p)));
1501 const double __d2x =
1503 / (__pi_4 * __pa)));
1507 const double __spi_2 = 1.2533141373155002512078826424055226L;
1508 _M_s1 =
std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1509 _M_s2 =
std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * (_M_t * __1p)));
1510 _M_c = 2 * _M_d1 / __np;
1511 _M_a1 =
std::exp(_M_c) * _M_s1 * __spi_2;
1512 const double __a12 = _M_a1 + _M_s2 * __spi_2;
1513 const double __s1s = _M_s1 * _M_s1;
1514 _M_a123 = __a12 + (
std::exp(_M_d1 / (_M_t * __1p))
1516 *
std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
1517 const double __s2s = _M_s2 * _M_s2;
1518 _M_s = (_M_a123 + 2 * __s2s / _M_d2
1519 *
std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
1520 _M_lf = (std::lgamma(__np + 1)
1521 + std::lgamma(_M_t - __np + 1));
1524 _M_q = -
std::log(1 - (__p12 - __pa) / __1p);
1531 template<
typename _IntType>
1532 template<
typename _UniformRandomNumberGenerator>
1534 binomial_distribution<_IntType>::
1535 _M_waiting(_UniformRandomNumberGenerator& __urng,
1536 _IntType __t,
double __q)
1540 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1547 const double __e = -
std::log(1.0 - __aurng());
1548 __sum += __e / (__t - __x);
1551 while (__sum <= __q);
1566 template<
typename _IntType>
1567 template<
typename _UniformRandomNumberGenerator>
1570 operator()(_UniformRandomNumberGenerator& __urng,
1574 const _IntType __t = __param.t();
1575 const double __p = __param.p();
1576 const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
1577 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1580#if _GLIBCXX_USE_C99_MATH_FUNCS
1581 if (!__param._M_easy)
1586 const double __naf =
1588 const double __thr =
1591 const double __np = std::floor(__t * __p12);
1594 const double __spi_2 = 1.2533141373155002512078826424055226L;
1595 const double __a1 = __param._M_a1;
1596 const double __a12 = __a1 + __param._M_s2 * __spi_2;
1597 const double __a123 = __param._M_a123;
1598 const double __s1s = __param._M_s1 * __param._M_s1;
1599 const double __s2s = __param._M_s2 * __param._M_s2;
1604 const double __u = __param._M_s * __aurng();
1610 const double __n = _M_nd(__urng);
1611 const double __y = __param._M_s1 *
std::abs(__n);
1612 __reject = __y >= __param._M_d1;
1615 const double __e = -
std::log(1.0 - __aurng());
1616 __x = std::floor(__y);
1617 __v = -__e - __n * __n / 2 + __param._M_c;
1620 else if (__u <= __a12)
1622 const double __n = _M_nd(__urng);
1623 const double __y = __param._M_s2 *
std::abs(__n);
1624 __reject = __y >= __param._M_d2;
1627 const double __e = -
std::log(1.0 - __aurng());
1628 __x = std::floor(-__y);
1629 __v = -__e - __n * __n / 2;
1632 else if (__u <= __a123)
1634 const double __e1 = -
std::log(1.0 - __aurng());
1635 const double __e2 = -
std::log(1.0 - __aurng());
1637 const double __y = __param._M_d1
1638 + 2 * __s1s * __e1 / __param._M_d1;
1639 __x = std::floor(__y);
1640 __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
1641 -__y / (2 * __s1s)));
1646 const double __e1 = -
std::log(1.0 - __aurng());
1647 const double __e2 = -
std::log(1.0 - __aurng());
1649 const double __y = __param._M_d2
1650 + 2 * __s2s * __e1 / __param._M_d2;
1651 __x = std::floor(-__y);
1652 __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
1656 __reject = __reject || __x < -__np || __x > __t - __np;
1659 const double __lfx =
1660 std::lgamma(__np + __x + 1)
1661 + std::lgamma(__t - (__np + __x) + 1);
1662 __reject = __v > __param._M_lf - __lfx
1663 + __x * __param._M_lp1p;
1666 __reject |= __x + __np >= __thr;
1670 __x += __np + __naf;
1672 const _IntType __z = _M_waiting(__urng, __t - _IntType(__x),
1674 __ret = _IntType(__x) + __z;
1678 __ret = _M_waiting(__urng, __t, __param._M_q);
1681 __ret = __t - __ret;
1685 template<
typename _IntType>
1686 template<
typename _ForwardIterator,
1687 typename _UniformRandomNumberGenerator>
1689 binomial_distribution<_IntType>::
1690 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1691 _UniformRandomNumberGenerator& __urng,
1694 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1700 template<
typename _IntType,
1701 typename _CharT,
typename _Traits>
1702 std::basic_ostream<_CharT, _Traits>&
1703 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1704 const binomial_distribution<_IntType>& __x)
1706 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1708 const typename __ios_base::fmtflags __flags = __os.
flags();
1709 const _CharT __fill = __os.
fill();
1711 const _CharT __space = __os.
widen(
' ');
1712 __os.
flags(__ios_base::scientific | __ios_base::left);
1714 __os.
precision(std::numeric_limits<double>::max_digits10);
1716 __os << __x.t() << __space << __x.p()
1717 << __space << __x._M_nd;
1719 __os.
flags(__flags);
1725 template<
typename _IntType,
1726 typename _CharT,
typename _Traits>
1727 std::basic_istream<_CharT, _Traits>&
1728 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1729 binomial_distribution<_IntType>& __x)
1731 using param_type =
typename binomial_distribution<_IntType>::param_type;
1732 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1734 const typename __ios_base::fmtflags __flags = __is.
flags();
1735 __is.
flags(__ios_base::dec | __ios_base::skipws);
1739 if (__is >> __t >> __p >> __x._M_nd)
1742 __is.
flags(__flags);
1747 template<
typename _RealType>
1748 template<
typename _ForwardIterator,
1749 typename _UniformRandomNumberGenerator>
1753 _UniformRandomNumberGenerator& __urng,
1754 const param_type& __p)
1756 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1757 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1763 template<
typename _RealType,
typename _CharT,
typename _Traits>
1766 const exponential_distribution<_RealType>& __x)
1768 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1770 const typename __ios_base::fmtflags __flags = __os.
flags();
1771 const _CharT __fill = __os.
fill();
1773 __os.
flags(__ios_base::scientific | __ios_base::left);
1777 __os << __x.lambda();
1779 __os.
flags(__flags);
1785 template<
typename _RealType,
typename _CharT,
typename _Traits>
1786 std::basic_istream<_CharT, _Traits>&
1792 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1794 const typename __ios_base::fmtflags __flags = __is.
flags();
1795 __is.
flags(__ios_base::dec | __ios_base::skipws);
1798 if (__is >> __lambda)
1799 __x.
param(param_type(__lambda));
1801 __is.
flags(__flags);
1812 template<
typename _RealType>
1813 template<
typename _UniformRandomNumberGenerator>
1816 operator()(_UniformRandomNumberGenerator& __urng,
1820 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1823 if (_M_saved_available)
1825 _M_saved_available =
false;
1835 __r2 = __x * __x + __y * __y;
1837 while (__r2 > 1.0 || __r2 == 0.0);
1840 _M_saved = __x * __mult;
1841 _M_saved_available =
true;
1842 __ret = __y * __mult;
1845 __ret = __ret * __param.stddev() + __param.mean();
1849 template<
typename _RealType>
1850 template<
typename _ForwardIterator,
1851 typename _UniformRandomNumberGenerator>
1855 _UniformRandomNumberGenerator& __urng,
1856 const param_type& __param)
1858 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1863 if (_M_saved_available)
1865 _M_saved_available =
false;
1866 *__f++ = _M_saved * __param.stddev() + __param.mean();
1872 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1875 while (__f + 1 < __t)
1877 result_type __x, __y, __r2;
1882 __r2 = __x * __x + __y * __y;
1884 while (__r2 > 1.0 || __r2 == 0.0);
1887 *__f++ = __y * __mult * __param.stddev() + __param.mean();
1888 *__f++ = __x * __mult * __param.stddev() + __param.mean();
1898 __r2 = __x * __x + __y * __y;
1900 while (__r2 > 1.0 || __r2 == 0.0);
1903 _M_saved = __x * __mult;
1904 _M_saved_available =
true;
1905 *__f = __y * __mult * __param.stddev() + __param.mean();
1909 template<
typename _RealType>
1911 operator==(
const std::normal_distribution<_RealType>& __d1,
1912 const std::normal_distribution<_RealType>& __d2)
1914 if (__d1._M_param == __d2._M_param
1915 && __d1._M_saved_available == __d2._M_saved_available)
1916 return __d1._M_saved_available ? __d1._M_saved == __d2._M_saved :
true;
1921 template<
typename _RealType,
typename _CharT,
typename _Traits>
1922 std::basic_ostream<_CharT, _Traits>&
1923 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1924 const normal_distribution<_RealType>& __x)
1926 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1928 const typename __ios_base::fmtflags __flags = __os.
flags();
1929 const _CharT __fill = __os.
fill();
1931 const _CharT __space = __os.
widen(
' ');
1932 __os.
flags(__ios_base::scientific | __ios_base::left);
1936 __os << __x.mean() << __space << __x.stddev()
1937 << __space << __x._M_saved_available;
1938 if (__x._M_saved_available)
1939 __os << __space << __x._M_saved;
1941 __os.
flags(__flags);
1947 template<
typename _RealType,
typename _CharT,
typename _Traits>
1948 std::basic_istream<_CharT, _Traits>&
1949 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1950 normal_distribution<_RealType>& __x)
1952 using param_type =
typename normal_distribution<_RealType>::param_type;
1953 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1955 const typename __ios_base::fmtflags __flags = __is.
flags();
1956 __is.
flags(__ios_base::dec | __ios_base::skipws);
1958 double __mean, __stddev;
1960 if (__is >> __mean >> __stddev >> __saved_avail)
1962 if (!__saved_avail || (__is >> __x._M_saved))
1964 __x._M_saved_available = __saved_avail;
1969 __is.
flags(__flags);
1974 template<
typename _RealType>
1975 template<
typename _ForwardIterator,
1976 typename _UniformRandomNumberGenerator>
1978 lognormal_distribution<_RealType>::
1979 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1980 _UniformRandomNumberGenerator& __urng,
1983 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1985 *__f++ =
std::exp(__p.s() * _M_nd(__urng) + __p.m());
1988 template<
typename _RealType,
typename _CharT,
typename _Traits>
1989 std::basic_ostream<_CharT, _Traits>&
1990 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1991 const lognormal_distribution<_RealType>& __x)
1993 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1995 const typename __ios_base::fmtflags __flags = __os.
flags();
1996 const _CharT __fill = __os.
fill();
1998 const _CharT __space = __os.
widen(
' ');
1999 __os.
flags(__ios_base::scientific | __ios_base::left);
2003 __os << __x.m() << __space << __x.s()
2004 << __space << __x._M_nd;
2006 __os.
flags(__flags);
2012 template<
typename _RealType,
typename _CharT,
typename _Traits>
2013 std::basic_istream<_CharT, _Traits>&
2014 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2015 lognormal_distribution<_RealType>& __x)
2018 =
typename lognormal_distribution<_RealType>::param_type;
2019 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2021 const typename __ios_base::fmtflags __flags = __is.
flags();
2022 __is.
flags(__ios_base::dec | __ios_base::skipws);
2025 if (__is >> __m >> __s >> __x._M_nd)
2028 __is.
flags(__flags);
2032 template<
typename _RealType>
2033 template<
typename _ForwardIterator,
2034 typename _UniformRandomNumberGenerator>
2036 std::chi_squared_distribution<_RealType>::
2037 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2038 _UniformRandomNumberGenerator& __urng)
2040 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2042 *__f++ = 2 * _M_gd(__urng);
2045 template<
typename _RealType>
2046 template<
typename _ForwardIterator,
2047 typename _UniformRandomNumberGenerator>
2049 std::chi_squared_distribution<_RealType>::
2050 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2051 _UniformRandomNumberGenerator& __urng,
2053 std::gamma_distribution<result_type>::param_type& __p)
2055 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2057 *__f++ = 2 * _M_gd(__urng, __p);
2060 template<
typename _RealType,
typename _CharT,
typename _Traits>
2061 std::basic_ostream<_CharT, _Traits>&
2062 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2063 const chi_squared_distribution<_RealType>& __x)
2065 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2067 const typename __ios_base::fmtflags __flags = __os.
flags();
2068 const _CharT __fill = __os.
fill();
2070 const _CharT __space = __os.
widen(
' ');
2071 __os.
flags(__ios_base::scientific | __ios_base::left);
2075 __os << __x.n() << __space << __x._M_gd;
2077 __os.
flags(__flags);
2083 template<
typename _RealType,
typename _CharT,
typename _Traits>
2084 std::basic_istream<_CharT, _Traits>&
2085 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2086 chi_squared_distribution<_RealType>& __x)
2089 =
typename chi_squared_distribution<_RealType>::param_type;
2090 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2092 const typename __ios_base::fmtflags __flags = __is.
flags();
2093 __is.
flags(__ios_base::dec | __ios_base::skipws);
2096 if (__is >> __n >> __x._M_gd)
2099 __is.
flags(__flags);
2104 template<
typename _RealType>
2105 template<
typename _UniformRandomNumberGenerator>
2108 operator()(_UniformRandomNumberGenerator& __urng,
2111 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2118 const _RealType __pi = 3.1415926535897932384626433832795029L;
2119 return __p.a() + __p.b() *
std::tan(__pi * __u);
2122 template<
typename _RealType>
2123 template<
typename _ForwardIterator,
2124 typename _UniformRandomNumberGenerator>
2128 _UniformRandomNumberGenerator& __urng,
2129 const param_type& __p)
2131 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2132 const _RealType __pi = 3.1415926535897932384626433832795029L;
2133 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2142 *__f++ = __p.a() + __p.b() *
std::tan(__pi * __u);
2146 template<
typename _RealType,
typename _CharT,
typename _Traits>
2149 const cauchy_distribution<_RealType>& __x)
2151 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2153 const typename __ios_base::fmtflags __flags = __os.
flags();
2154 const _CharT __fill = __os.
fill();
2156 const _CharT __space = __os.
widen(
' ');
2157 __os.
flags(__ios_base::scientific | __ios_base::left);
2161 __os << __x.a() << __space << __x.b();
2163 __os.
flags(__flags);
2169 template<
typename _RealType,
typename _CharT,
typename _Traits>
2170 std::basic_istream<_CharT, _Traits>&
2175 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2177 const typename __ios_base::fmtflags __flags = __is.
flags();
2178 __is.
flags(__ios_base::dec | __ios_base::skipws);
2181 if (__is >> __a >> __b)
2182 __x.
param(param_type(__a, __b));
2184 __is.
flags(__flags);
2189 template<
typename _RealType>
2190 template<
typename _ForwardIterator,
2191 typename _UniformRandomNumberGenerator>
2195 _UniformRandomNumberGenerator& __urng)
2197 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2199 *__f++ = ((_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()));
2202 template<
typename _RealType>
2203 template<
typename _ForwardIterator,
2204 typename _UniformRandomNumberGenerator>
2206 std::fisher_f_distribution<_RealType>::
2207 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2208 _UniformRandomNumberGenerator& __urng,
2211 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2212 typedef typename std::gamma_distribution<result_type>::param_type
2217 *__f++ = ((_M_gd_x(__urng, __p1) * n())
2218 / (_M_gd_y(__urng, __p2) * m()));
2221 template<
typename _RealType,
typename _CharT,
typename _Traits>
2222 std::basic_ostream<_CharT, _Traits>&
2223 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2224 const fisher_f_distribution<_RealType>& __x)
2226 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2228 const typename __ios_base::fmtflags __flags = __os.
flags();
2229 const _CharT __fill = __os.
fill();
2231 const _CharT __space = __os.
widen(
' ');
2232 __os.
flags(__ios_base::scientific | __ios_base::left);
2236 __os << __x.m() << __space << __x.n()
2237 << __space << __x._M_gd_x << __space << __x._M_gd_y;
2239 __os.
flags(__flags);
2245 template<
typename _RealType,
typename _CharT,
typename _Traits>
2252 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2254 const typename __ios_base::fmtflags __flags = __is.
flags();
2255 __is.
flags(__ios_base::dec | __ios_base::skipws);
2258 if (__is >> __m >> __n >> __x._M_gd_x >> __x._M_gd_y)
2259 __x.
param(param_type(__m, __n));
2261 __is.
flags(__flags);
2266 template<
typename _RealType>
2267 template<
typename _ForwardIterator,
2268 typename _UniformRandomNumberGenerator>
2272 _UniformRandomNumberGenerator& __urng)
2274 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2276 *__f++ = _M_nd(__urng) *
std::sqrt(n() / _M_gd(__urng));
2279 template<
typename _RealType>
2280 template<
typename _ForwardIterator,
2281 typename _UniformRandomNumberGenerator>
2283 std::student_t_distribution<_RealType>::
2284 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2285 _UniformRandomNumberGenerator& __urng,
2288 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2289 typename std::gamma_distribution<result_type>::param_type
2290 __p2(__p.n() / 2, 2);
2292 *__f++ = _M_nd(__urng) *
std::sqrt(__p.n() / _M_gd(__urng, __p2));
2295 template<
typename _RealType,
typename _CharT,
typename _Traits>
2296 std::basic_ostream<_CharT, _Traits>&
2297 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2298 const student_t_distribution<_RealType>& __x)
2300 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2302 const typename __ios_base::fmtflags __flags = __os.
flags();
2303 const _CharT __fill = __os.
fill();
2305 const _CharT __space = __os.
widen(
' ');
2306 __os.
flags(__ios_base::scientific | __ios_base::left);
2310 __os << __x.n() << __space << __x._M_nd << __space << __x._M_gd;
2312 __os.
flags(__flags);
2318 template<
typename _RealType,
typename _CharT,
typename _Traits>
2319 std::basic_istream<_CharT, _Traits>&
2320 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2321 student_t_distribution<_RealType>& __x)
2324 =
typename student_t_distribution<_RealType>::param_type;
2325 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2327 const typename __ios_base::fmtflags __flags = __is.
flags();
2328 __is.
flags(__ios_base::dec | __ios_base::skipws);
2331 if (__is >> __n >> __x._M_nd >> __x._M_gd)
2334 __is.
flags(__flags);
2339 template<
typename _RealType>
2341 gamma_distribution<_RealType>::param_type::
2344 _M_malpha = _M_alpha < 1.0 ? _M_alpha + _RealType(1.0) : _M_alpha;
2346 const _RealType __a1 = _M_malpha - _RealType(1.0) / _RealType(3.0);
2347 _M_a2 = _RealType(1.0) /
std::sqrt(_RealType(9.0) * __a1);
2355 template<
typename _RealType>
2356 template<
typename _UniformRandomNumberGenerator>
2359 operator()(_UniformRandomNumberGenerator& __urng,
2362 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2367 - _RealType(1.0) / _RealType(3.0));
2373 __n = _M_nd(__urng);
2378 __v = __v * __v * __v;
2381 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2382 && (
std::log(__u) > (0.5 * __n * __n + __a1
2385 if (__param.alpha() == __param._M_malpha)
2386 return __a1 * __v * __param.beta();
2394 * __a1 * __v * __param.beta());
2398 template<
typename _RealType>
2399 template<
typename _ForwardIterator,
2400 typename _UniformRandomNumberGenerator>
2404 _UniformRandomNumberGenerator& __urng,
2405 const param_type& __param)
2407 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2408 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2411 result_type __u, __v, __n;
2412 const result_type __a1 = (__param._M_malpha
2413 - _RealType(1.0) / _RealType(3.0));
2415 if (__param.alpha() == __param._M_malpha)
2422 __n = _M_nd(__urng);
2427 __v = __v * __v * __v;
2430 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2431 && (
std::log(__u) > (0.5 * __n * __n + __a1
2434 *__f++ = __a1 * __v * __param.beta();
2443 __n = _M_nd(__urng);
2448 __v = __v * __v * __v;
2451 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2452 && (
std::log(__u) > (0.5 * __n * __n + __a1
2460 * __a1 * __v * __param.beta());
2464 template<
typename _RealType,
typename _CharT,
typename _Traits>
2465 std::basic_ostream<_CharT, _Traits>&
2466 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2467 const gamma_distribution<_RealType>& __x)
2469 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2471 const typename __ios_base::fmtflags __flags = __os.
flags();
2472 const _CharT __fill = __os.
fill();
2474 const _CharT __space = __os.
widen(
' ');
2475 __os.
flags(__ios_base::scientific | __ios_base::left);
2479 __os << __x.alpha() << __space << __x.beta()
2480 << __space << __x._M_nd;
2482 __os.
flags(__flags);
2488 template<
typename _RealType,
typename _CharT,
typename _Traits>
2489 std::basic_istream<_CharT, _Traits>&
2490 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2491 gamma_distribution<_RealType>& __x)
2493 using param_type =
typename gamma_distribution<_RealType>::param_type;
2494 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2496 const typename __ios_base::fmtflags __flags = __is.
flags();
2497 __is.
flags(__ios_base::dec | __ios_base::skipws);
2499 _RealType __alpha_val, __beta_val;
2500 if (__is >> __alpha_val >> __beta_val >> __x._M_nd)
2501 __x.param(
param_type(__alpha_val, __beta_val));
2503 __is.
flags(__flags);
2508 template<
typename _RealType>
2509 template<
typename _UniformRandomNumberGenerator>
2512 operator()(_UniformRandomNumberGenerator& __urng,
2515 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2521 template<
typename _RealType>
2522 template<
typename _ForwardIterator,
2523 typename _UniformRandomNumberGenerator>
2527 _UniformRandomNumberGenerator& __urng,
2528 const param_type& __p)
2530 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2531 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2540 template<
typename _RealType,
typename _CharT,
typename _Traits>
2543 const weibull_distribution<_RealType>& __x)
2545 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2547 const typename __ios_base::fmtflags __flags = __os.
flags();
2548 const _CharT __fill = __os.
fill();
2550 const _CharT __space = __os.
widen(
' ');
2551 __os.
flags(__ios_base::scientific | __ios_base::left);
2555 __os << __x.a() << __space << __x.b();
2557 __os.
flags(__flags);
2563 template<
typename _RealType,
typename _CharT,
typename _Traits>
2564 std::basic_istream<_CharT, _Traits>&
2569 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2571 const typename __ios_base::fmtflags __flags = __is.
flags();
2572 __is.
flags(__ios_base::dec | __ios_base::skipws);
2575 if (__is >> __a >> __b)
2576 __x.
param(param_type(__a, __b));
2578 __is.
flags(__flags);
2583 template<
typename _RealType>
2584 template<
typename _UniformRandomNumberGenerator>
2587 operator()(_UniformRandomNumberGenerator& __urng,
2588 const param_type& __p)
2590 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2596 template<
typename _RealType>
2597 template<
typename _ForwardIterator,
2598 typename _UniformRandomNumberGenerator>
2602 _UniformRandomNumberGenerator& __urng,
2603 const param_type& __p)
2605 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2606 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2614 template<
typename _RealType,
typename _CharT,
typename _Traits>
2617 const extreme_value_distribution<_RealType>& __x)
2619 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2621 const typename __ios_base::fmtflags __flags = __os.
flags();
2622 const _CharT __fill = __os.
fill();
2624 const _CharT __space = __os.
widen(
' ');
2625 __os.
flags(__ios_base::scientific | __ios_base::left);
2629 __os << __x.a() << __space << __x.b();
2631 __os.
flags(__flags);
2637 template<
typename _RealType,
typename _CharT,
typename _Traits>
2638 std::basic_istream<_CharT, _Traits>&
2644 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2646 const typename __ios_base::fmtflags __flags = __is.
flags();
2647 __is.
flags(__ios_base::dec | __ios_base::skipws);
2650 if (__is >> __a >> __b)
2651 __x.
param(param_type(__a, __b));
2653 __is.
flags(__flags);
2658 template<
typename _IntType>
2660 discrete_distribution<_IntType>::param_type::
2663 if (_M_prob.size() < 2)
2670 _M_prob.end(), 0.0);
2671 __glibcxx_assert(__sum > 0);
2673 __detail::__normalize(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
2676 _M_cp.reserve(_M_prob.size());
2680 _M_cp[_M_cp.size() - 1] = 1.0;
2683 template<
typename _IntType>
2684 template<
typename _Func>
2685 discrete_distribution<_IntType>::param_type::
2686 param_type(
size_t __nw,
double __xmin,
double __xmax, _Func __fw)
2687 : _M_prob(), _M_cp()
2689 const size_t __n = __nw == 0 ? 1 : __nw;
2690 const double __delta = (__xmax - __xmin) / __n;
2692 _M_prob.reserve(__n);
2693 for (
size_t __k = 0; __k < __nw; ++__k)
2694 _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
2699 template<
typename _IntType>
2700 template<
typename _UniformRandomNumberGenerator>
2701 typename discrete_distribution<_IntType>::result_type
2702 discrete_distribution<_IntType>::
2703 operator()(_UniformRandomNumberGenerator& __urng,
2704 const param_type& __param)
2706 if (__param._M_cp.empty())
2709 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2712 const double __p = __aurng();
2713 auto __pos = std::lower_bound(__param._M_cp.begin(),
2714 __param._M_cp.end(), __p);
2716 return __pos - __param._M_cp.begin();
2719 template<
typename _IntType>
2720 template<
typename _ForwardIterator,
2721 typename _UniformRandomNumberGenerator>
2725 _UniformRandomNumberGenerator& __urng,
2726 const param_type& __param)
2728 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2730 if (__param._M_cp.empty())
2733 *__f++ = result_type(0);
2737 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2742 const double __p = __aurng();
2743 auto __pos = std::lower_bound(__param._M_cp.begin(),
2744 __param._M_cp.end(), __p);
2746 *__f++ = __pos - __param._M_cp.begin();
2750 template<
typename _IntType,
typename _CharT,
typename _Traits>
2753 const discrete_distribution<_IntType>& __x)
2755 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2757 const typename __ios_base::fmtflags __flags = __os.
flags();
2758 const _CharT __fill = __os.
fill();
2760 const _CharT __space = __os.
widen(
' ');
2761 __os.
flags(__ios_base::scientific | __ios_base::left);
2766 __os << __prob.
size();
2767 for (
auto __dit = __prob.
begin(); __dit != __prob.
end(); ++__dit)
2768 __os << __space << *__dit;
2770 __os.
flags(__flags);
2778 template<
typename _ValT,
typename _CharT,
typename _Traits>
2779 basic_istream<_CharT, _Traits>&
2780 __extract_params(basic_istream<_CharT, _Traits>& __is,
2781 vector<_ValT>& __vals,
size_t __n)
2783 __vals.reserve(__n);
2788 __vals.push_back(__val);
2796 template<
typename _IntType,
typename _CharT,
typename _Traits>
2799 discrete_distribution<_IntType>& __x)
2801 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2803 const typename __ios_base::fmtflags __flags = __is.
flags();
2804 __is.
flags(__ios_base::dec | __ios_base::skipws);
2810 if (__detail::__extract_params(__is, __prob_vec, __n))
2811 __x.param({__prob_vec.
begin(), __prob_vec.
end()});
2814 __is.
flags(__flags);
2819 template<
typename _RealType>
2821 piecewise_constant_distribution<_RealType>::param_type::
2824 if (_M_int.size() < 2
2825 || (_M_int.size() == 2
2826 && _M_int[0] == _RealType(0)
2827 && _M_int[1] == _RealType(1)))
2836 __glibcxx_assert(__sum > 0);
2838 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
2841 _M_cp.reserve(_M_den.size());
2846 _M_cp[_M_cp.size() - 1] = 1.0;
2848 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2849 _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
2852 template<
typename _RealType>
2853 template<
typename _InputIteratorB,
typename _InputIteratorW>
2854 piecewise_constant_distribution<_RealType>::param_type::
2855 param_type(_InputIteratorB __bbegin,
2856 _InputIteratorB __bend,
2857 _InputIteratorW __wbegin)
2858 : _M_int(), _M_den(), _M_cp()
2860 if (__bbegin != __bend)
2864 _M_int.push_back(*__bbegin);
2866 if (__bbegin == __bend)
2869 _M_den.push_back(*__wbegin);
2877 template<
typename _RealType>
2878 template<
typename _Func>
2881 : _M_int(), _M_den(), _M_cp()
2883 _M_int.reserve(__bl.size());
2884 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
2885 _M_int.push_back(*__biter);
2887 _M_den.reserve(_M_int.size() - 1);
2888 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
2889 _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
2894 template<
typename _RealType>
2895 template<
typename _Func>
2897 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
2898 : _M_int(), _M_den(), _M_cp()
2900 const size_t __n = __nw == 0 ? 1 : __nw;
2901 const _RealType __delta = (__xmax - __xmin) / __n;
2903 _M_int.reserve(__n + 1);
2904 for (
size_t __k = 0; __k <= __nw; ++__k)
2905 _M_int.push_back(__xmin + __k * __delta);
2907 _M_den.reserve(__n);
2908 for (
size_t __k = 0; __k < __nw; ++__k)
2909 _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
2914 template<
typename _RealType>
2915 template<
typename _UniformRandomNumberGenerator>
2918 operator()(_UniformRandomNumberGenerator& __urng,
2919 const param_type& __param)
2921 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2924 const double __p = __aurng();
2925 if (__param._M_cp.empty())
2928 auto __pos = std::lower_bound(__param._M_cp.begin(),
2929 __param._M_cp.end(), __p);
2930 const size_t __i = __pos - __param._M_cp.begin();
2932 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2934 return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
2937 template<
typename _RealType>
2938 template<
typename _ForwardIterator,
2939 typename _UniformRandomNumberGenerator>
2943 _UniformRandomNumberGenerator& __urng,
2944 const param_type& __param)
2946 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2947 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2950 if (__param._M_cp.empty())
2959 const double __p = __aurng();
2961 auto __pos = std::lower_bound(__param._M_cp.begin(),
2962 __param._M_cp.end(), __p);
2963 const size_t __i = __pos - __param._M_cp.begin();
2965 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
2967 *__f++ = (__param._M_int[__i]
2968 + (__p - __pref) / __param._M_den[__i]);
2972 template<
typename _RealType,
typename _CharT,
typename _Traits>
2973 std::basic_ostream<_CharT, _Traits>&
2974 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2977 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2979 const typename __ios_base::fmtflags __flags = __os.
flags();
2980 const _CharT __fill = __os.
fill();
2982 const _CharT __space = __os.
widen(
' ');
2983 __os.
flags(__ios_base::scientific | __ios_base::left);
2987 std::vector<_RealType> __int = __x.intervals();
2988 __os << __int.
size() - 1;
2990 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
2991 __os << __space << *__xit;
2993 std::vector<double> __den = __x.densities();
2994 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
2995 __os << __space << *__dit;
2997 __os.
flags(__flags);
3003 template<
typename _RealType,
typename _CharT,
typename _Traits>
3004 std::basic_istream<_CharT, _Traits>&
3005 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3008 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3010 const typename __ios_base::fmtflags __flags = __is.
flags();
3011 __is.
flags(__ios_base::dec | __ios_base::skipws);
3016 std::vector<_RealType> __int_vec;
3017 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3019 std::vector<double> __den_vec;
3020 if (__detail::__extract_params(__is, __den_vec, __n))
3022 __x.param({ __int_vec.
begin(), __int_vec.
end(),
3023 __den_vec.
begin() });
3028 __is.
flags(__flags);
3033 template<
typename _RealType>
3038 if (_M_int.size() < 2
3039 || (_M_int.size() == 2
3040 && _M_int[0] == _RealType(0)
3041 && _M_int[1] == _RealType(1)
3042 && _M_den[0] == _M_den[1]))
3050 _M_cp.reserve(_M_int.size() - 1);
3051 _M_m.reserve(_M_int.size() - 1);
3052 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3054 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
3055 __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
3056 _M_cp.push_back(__sum);
3057 _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
3059 __glibcxx_assert(__sum > 0);
3062 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
3065 __detail::__normalize(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), __sum);
3067 __detail::__normalize(_M_m.begin(), _M_m.end(), _M_m.begin(), __sum);
3070 _M_cp[_M_cp.size() - 1] = 1.0;
3073 template<
typename _RealType>
3074 template<
typename _InputIteratorB,
typename _InputIteratorW>
3075 piecewise_linear_distribution<_RealType>::param_type::
3076 param_type(_InputIteratorB __bbegin,
3077 _InputIteratorB __bend,
3078 _InputIteratorW __wbegin)
3079 : _M_int(), _M_den(), _M_cp(), _M_m()
3081 for (; __bbegin != __bend; ++__bbegin, ++__wbegin)
3083 _M_int.push_back(*__bbegin);
3084 _M_den.push_back(*__wbegin);
3090 template<
typename _RealType>
3091 template<
typename _Func>
3094 : _M_int(), _M_den(), _M_cp(), _M_m()
3096 _M_int.reserve(__bl.size());
3097 _M_den.reserve(__bl.size());
3098 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3100 _M_int.push_back(*__biter);
3101 _M_den.push_back(__fw(*__biter));
3107 template<
typename _RealType>
3108 template<
typename _Func>
3110 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3111 : _M_int(), _M_den(), _M_cp(), _M_m()
3113 const size_t __n = __nw == 0 ? 1 : __nw;
3114 const _RealType __delta = (__xmax - __xmin) / __n;
3116 _M_int.reserve(__n + 1);
3117 _M_den.reserve(__n + 1);
3118 for (
size_t __k = 0; __k <= __nw; ++__k)
3120 _M_int.push_back(__xmin + __k * __delta);
3121 _M_den.push_back(__fw(_M_int[__k] + __delta));
3127 template<
typename _RealType>
3128 template<
typename _UniformRandomNumberGenerator>
3131 operator()(_UniformRandomNumberGenerator& __urng,
3132 const param_type& __param)
3134 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3137 const double __p = __aurng();
3138 if (__param._M_cp.empty())
3141 auto __pos = std::lower_bound(__param._M_cp.begin(),
3142 __param._M_cp.end(), __p);
3143 const size_t __i = __pos - __param._M_cp.begin();
3145 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3147 const double __a = 0.5 * __param._M_m[__i];
3148 const double __b = __param._M_den[__i];
3149 const double __cm = __p - __pref;
3151 _RealType __x = __param._M_int[__i];
3156 const double __d = __b * __b + 4.0 * __a * __cm;
3157 __x += 0.5 * (
std::sqrt(__d) - __b) / __a;
3163 template<
typename _RealType>
3164 template<
typename _ForwardIterator,
3165 typename _UniformRandomNumberGenerator>
3169 _UniformRandomNumberGenerator& __urng,
3170 const param_type& __param)
3172 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3175 *__f++ = this->operator()(__urng, __param);
3178 template<
typename _RealType,
typename _CharT,
typename _Traits>
3179 std::basic_ostream<_CharT, _Traits>&
3180 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
3183 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
3185 const typename __ios_base::fmtflags __flags = __os.
flags();
3186 const _CharT __fill = __os.
fill();
3188 const _CharT __space = __os.
widen(
' ');
3189 __os.
flags(__ios_base::scientific | __ios_base::left);
3193 std::vector<_RealType> __int = __x.intervals();
3194 __os << __int.
size() - 1;
3196 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3197 __os << __space << *__xit;
3199 std::vector<double> __den = __x.densities();
3200 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3201 __os << __space << *__dit;
3203 __os.
flags(__flags);
3209 template<
typename _RealType,
typename _CharT,
typename _Traits>
3210 std::basic_istream<_CharT, _Traits>&
3211 operator>>(std::basic_istream<_CharT, _Traits>& __is,
3214 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3216 const typename __ios_base::fmtflags __flags = __is.
flags();
3217 __is.
flags(__ios_base::dec | __ios_base::skipws);
3223 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3226 if (__detail::__extract_params(__is, __den_vec, __n + 1))
3228 __x.param({ __int_vec.begin(), __int_vec.end(),
3229 __den_vec.begin() });
3233 __is.
flags(__flags);
3238 template<
typename _IntType,
typename>
3241 _M_v.reserve(__il.size());
3242 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
3244 __detail::_Shift<result_type, 32>::__value>(*__iter));
3247 template<
typename _InputIterator>
3250#pragma GCC diagnostic push
3251#pragma GCC diagnostic ignored "-Wc++17-extensions"
3252 if constexpr (__is_random_access_iter<_InputIterator>::value)
3254#pragma GCC diagnostic pop
3256 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
3258 __detail::_Shift<result_type, 32>::__value>(*__iter));
3261 template<
typename _RandomAccessIterator>
3263 seed_seq::generate(_RandomAccessIterator __begin,
3264 _RandomAccessIterator __end)
3266 typedef typename iterator_traits<_RandomAccessIterator>::value_type
3269 if (__begin == __end)
3272 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
3274 const size_t __n = __end - __begin;
3275 const size_t __s = _M_v.size();
3276 const size_t __t = (__n >= 623) ? 11
3281 const size_t __p = (__n - __t) / 2;
3282 const size_t __q = __p + __t;
3283 const size_t __m =
std::max(
size_t(__s + 1), __n);
3285#ifndef __UINT32_TYPE__
3288 _Up(uint_least32_t v) : _M_v(v & 0xffffffffu) { }
3290 operator uint_least32_t()
const {
return _M_v; }
3292 uint_least32_t _M_v;
3294 using uint32_t = _Up;
3299 uint32_t __r1 = 1371501266u;
3300 uint32_t __r2 = __r1 + __s;
3301 __begin[__p] += __r1;
3302 __begin[__q] = (uint32_t)__begin[__q] + __r2;
3306 for (
size_t __k = 1; __k <= __s; ++__k)
3308 const size_t __kn = __k % __n;
3309 const size_t __kpn = (__k + __p) % __n;
3310 const size_t __kqn = (__k + __q) % __n;
3311 uint32_t __arg = (__begin[__kn]
3313 ^ __begin[(__k - 1) % __n]);
3314 uint32_t __r1 = 1664525u * (__arg ^ (__arg >> 27));
3315 uint32_t __r2 = __r1 + (uint32_t)__kn + _M_v[__k - 1];
3316 __begin[__kpn] = (uint32_t)__begin[__kpn] + __r1;
3317 __begin[__kqn] = (uint32_t)__begin[__kqn] + __r2;
3318 __begin[__kn] = __r2;
3321 for (
size_t __k = __s + 1; __k < __m; ++__k)
3323 const size_t __kn = __k % __n;
3324 const size_t __kpn = (__k + __p) % __n;
3325 const size_t __kqn = (__k + __q) % __n;
3326 uint32_t __arg = (__begin[__kn]
3328 ^ __begin[(__k - 1) % __n]);
3329 uint32_t __r1 = 1664525u * (__arg ^ (__arg >> 27));
3330 uint32_t __r2 = __r1 + (uint32_t)__kn;
3331 __begin[__kpn] = (uint32_t)__begin[__kpn] + __r1;
3332 __begin[__kqn] = (uint32_t)__begin[__kqn] + __r2;
3333 __begin[__kn] = __r2;
3336 for (
size_t __k = __m; __k < __m + __n; ++__k)
3338 const size_t __kn = __k % __n;
3339 const size_t __kpn = (__k + __p) % __n;
3340 const size_t __kqn = (__k + __q) % __n;
3341 uint32_t __arg = (__begin[__kn]
3343 + __begin[(__k - 1) % __n]);
3344 uint32_t __r3 = 1566083941u * (__arg ^ (__arg >> 27));
3345 uint32_t __r4 = __r3 - __kn;
3346 __begin[__kpn] ^= __r3;
3347 __begin[__kqn] ^= __r4;
3348 __begin[__kn] = __r4;
3352 template<
typename _RealType,
size_t __bits,
3353 typename _UniformRandomNumberGenerator>
3358 "template argument must be a floating point type");
3363 const long double __r =
static_cast<long double>(__urng.max())
3364 -
static_cast<long double>(__urng.min()) + 1.0L;
3367 (__b + __log2r - 1UL) / __log2r);
3369 _RealType __sum = _RealType(0);
3370 _RealType __tmp = _RealType(1);
3371 for (
size_t __k = __m; __k != 0; --__k)
3373 __sum += _RealType(__urng() - __urng.min()) * __tmp;
3376 __ret = __sum / __tmp;
3377 if (__builtin_expect(__ret >= _RealType(1), 0))
3379#if _GLIBCXX_USE_C99_MATH_FUNCS
3380 __ret = std::nextafter(_RealType(1), _RealType(0));
3382 __ret = _RealType(1)
3389_GLIBCXX_END_NAMESPACE_VERSION
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
complex< _Tp > tan(const complex< _Tp > &)
Return complex tangent of z.
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
_RealType generate_canonical(_UniformRandomNumberGenerator &__g)
A function template for converting the output of a (integral) uniform random number generator to a fl...
constexpr back_insert_iterator< _Container > back_inserter(_Container &__x)
constexpr _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Accumulate values in a range.
constexpr _OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return list of partial sums.
ISO C++ entities toplevel namespace is std.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr _Tp __lg(_Tp __n)
This is a helper function for the sort routines and for random.tcc.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Implementation details not part of the namespace std interface.
char_type widen(char __c) const
Widens characters.
char_type fill() const
Retrieves the empty character.
Template class basic_istream.
Template class basic_ostream.
static constexpr bool is_integer
static constexpr int max_digits10
static constexpr int digits
static constexpr bool is_signed
static constexpr _Tp max() noexcept
static constexpr _Tp epsilon() noexcept
streamsize precision() const
Flags access.
fmtflags flags() const
Access to format flags.
A model of a linear congruential random number generator.
static constexpr result_type multiplier
static constexpr result_type modulus
void seed(result_type __s=default_seed)
Reseeds the linear_congruential_engine random number generator engine sequence to the seed __s.
static constexpr result_type increment
std::mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL >::result_type uint_fast32_t result_type
The Marsaglia-Zaman generator.
void seed(result_type __sd=0u)
Seeds the initial state of the random number generator.
result_type operator()()
Gets the next random number in the sequence.
result_type operator()()
Gets the next value in the generated random number sequence.
result_type operator()()
Gets the next value in the generated random number sequence.
Produces random numbers by reordering random numbers from some base engine.
const _RandomNumberEngine & base() const noexcept
_RandomNumberEngine::result_type result_type
Uniform continuous distribution for random numbers.
param_type param() const
Returns the parameter set of the distribution.
A normal continuous distribution for random numbers.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A gamma continuous distribution for random numbers.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A cauchy_distribution random number distribution.
param_type param() const
Returns the parameter set of the distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A fisher_f_distribution random number distribution.
param_type param() const
Returns the parameter set of the distribution.
A student_t_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A discrete geometric random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
param_type param() const
Returns the parameter set of the distribution.
A negative_binomial_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A discrete Poisson random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
friend bool operator==(const poisson_distribution &__d1, const poisson_distribution &__d2)
Return true if two Poisson distributions have the same parameters and the sequences that would be gen...
friend std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const std::poisson_distribution< _IntType1 > &__x)
Inserts a poisson_distribution random number distribution __x into the output stream __os.
friend std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, std::poisson_distribution< _IntType1 > &__x)
Extracts a poisson_distribution random number distribution __x from the input stream __is.
An exponential continuous distribution for random numbers.
param_type param() const
Returns the parameter set of the distribution.
A weibull_distribution random number distribution.
param_type param() const
Returns the parameter set of the distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A extreme_value_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
param_type param() const
Returns the parameter set of the distribution.
A discrete_distribution random number distribution.
A piecewise_constant_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
A piecewise_linear_distribution random number distribution.
result_type operator()(_UniformRandomNumberGenerator &__urng)
Generating functions.
uint_least32_t result_type
A standard container which offers fixed time access to individual elements in any order.
constexpr iterator end() noexcept
constexpr iterator begin() noexcept
constexpr size_type size() const noexcept
Uniform discrete distribution for random numbers. A discrete random distribution on the range with e...
param_type param() const
Returns the parameter set of the distribution.