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 _RealType& __factor)
86 for (; __first != __last; ++__first, (void) ++__result)
87 *__result = _RealType(_RealType(*__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>
688 __p, __r>::result_type
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>
894 shuffle_order_engine<_RandomNumberEngine, __k>& __x)
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];
910#if __glibcxx_philox_engine
912 template<
typename _UIntType,
size_t __w,
size_t __n,
size_t __r,
913 _UIntType... __consts>
916 _S_mulhi(_UIntType __a, _UIntType __b)
918 using __type =
typename __detail::_Select_uint_least_t<__w * 2>::type;
919 const __type __num =
static_cast<__type
>(__a) * __b;
920 return static_cast<_UIntType
>(__num >> __w) &
max();
923 template<
typename _UIntType,
size_t __w,
size_t __n,
size_t __r,
924 _UIntType... __consts>
927 _S_mullo(_UIntType __a, _UIntType __b)
929 return static_cast<_UIntType
>((__a * __b) &
max());
932 template<
typename _UIntType,
size_t __w,
size_t __n,
size_t __r,
933 _UIntType... __consts>
935 philox_engine<_UIntType, __w, __n, __r, __consts...>::_M_transition()
941 using __type =
typename __detail::_Select_uint_least_t<__w * 2>::type;
944 if constexpr (__n == 4)
947 = (
static_cast<__type
>(_M_x[1]) << __w)
948 |
static_cast<__type
>(_M_x[0]);
951 = (
static_cast<__type
>(_M_x[3]) << __w)
952 |
static_cast<__type
>(_M_x[2]);
954 = ~__type(0) >> ((
sizeof(__type) * __CHAR_BIT__) - (__w * 2));
955 if ((__uh & __bigMask) == 0)
960 _M_x[0] =
static_cast<_UIntType
>(__uh &
max());
961 _M_x[1] =
static_cast<_UIntType
>((__uh >> (__w)) &
max());
962 _M_x[2] =
static_cast<_UIntType
>(__lh &
max());
963 _M_x[3] =
static_cast<_UIntType
>((__lh >> (__w)) &
max());
968 = (
static_cast<__type
>(_M_x[1]) << __w)
969 |
static_cast<__type
>(_M_x[0]);
971 _M_x[0] =
static_cast<_UIntType
>(__num &
max());
972 _M_x[1] =
static_cast<_UIntType
>((__num >> __w) &
max());
977 template<
typename _UIntType,
size_t __w,
size_t __n,
size_t __r,
978 _UIntType... __consts>
980 philox_engine<_UIntType, __w, __n, __r, __consts...>::_M_philox()
983 for (
size_t __j = 0; __j < __r; ++__j)
986 if constexpr (__n == 4)
988 __intermedSeq[0] = __outputSeq[2];
989 __intermedSeq[1] = __outputSeq[1];
990 __intermedSeq[2] = __outputSeq[0];
991 __intermedSeq[3] = __outputSeq[3];
995 __intermedSeq[0] = __outputSeq[0];
996 __intermedSeq[1] = __outputSeq[1];
998 for (
unsigned long __k = 0; __k < (__n/2); ++__k)
1001 = _S_mulhi(__intermedSeq[2*__k], multipliers[__k])
1002 ^ (((_M_k[__k] + (__j * round_consts[__k])) &
max()))
1003 ^ __intermedSeq[2*__k+1];
1005 __outputSeq[(2*__k)+1]
1006 = _S_mullo(__intermedSeq[2*__k], multipliers[__k]);
1012 template<
typename _UIntType,
size_t __w,
size_t __n,
size_t __r,
1013 _UIntType... __consts>
1014 template<
typename _Sseq>
1016 philox_engine<_UIntType, __w, __n, __r, __consts...>::seed(_Sseq& __q)
1017 requires __is_seed_seq<_Sseq>
1021 const unsigned __p = 1 + ((__w - 1) / 32);
1022 uint_least32_t __tmpArr[(__n/2) * __p];
1023 __q.generate(__tmpArr + 0, __tmpArr + ((__n/2) * __p));
1024 for (
unsigned __k = 0; __k < (__n/2); ++__k)
1026 unsigned long long __precalc = 0;
1027 for (
unsigned __j = 0; __j < __p; ++__j)
1029 unsigned long long __multiplicand = (1ull << (32 * __j));
1030 __precalc += (__tmpArr[__k * __p + __j] * __multiplicand) &
max();
1032 _M_k[__k] = __precalc;
1037 template<
typename _IntType,
typename _CharT,
typename _Traits>
1042 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1044 const typename __ios_base::fmtflags __flags = __os.
flags();
1045 const _CharT __fill = __os.
fill();
1046 const _CharT __space = __os.
widen(
' ');
1047 __os.
flags(__ios_base::scientific | __ios_base::left);
1050 __os << __x.a() << __space << __x.b();
1052 __os.
flags(__flags);
1057 template<
typename _IntType,
typename _CharT,
typename _Traits>
1064 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1066 const typename __ios_base::fmtflags __flags = __is.
flags();
1067 __is.
flags(__ios_base::dec | __ios_base::skipws);
1070 if (__is >> __a >> __b)
1071 __x.
param(param_type(__a, __b));
1073 __is.
flags(__flags);
1078 template<
typename _RealType>
1079 template<
typename _ForwardIterator,
1080 typename _UniformRandomNumberGenerator>
1084 _UniformRandomNumberGenerator& __urng,
1085 const param_type& __p)
1087 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1088 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1090 auto __range = __p.b() - __p.a();
1092 *__f++ = __aurng() * __range + __p.a();
1095 template<
typename _RealType,
typename _CharT,
typename _Traits>
1098 const uniform_real_distribution<_RealType>& __x)
1100 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1102 const typename __ios_base::fmtflags __flags = __os.
flags();
1103 const _CharT __fill = __os.
fill();
1105 const _CharT __space = __os.
widen(
' ');
1106 __os.
flags(__ios_base::scientific | __ios_base::left);
1110 __os << __x.a() << __space << __x.b();
1112 __os.
flags(__flags);
1118 template<
typename _RealType,
typename _CharT,
typename _Traits>
1119 std::basic_istream<_CharT, _Traits>&
1125 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1127 const typename __ios_base::fmtflags __flags = __is.
flags();
1128 __is.
flags(__ios_base::skipws);
1131 if (__is >> __a >> __b)
1132 __x.
param(param_type(__a, __b));
1134 __is.
flags(__flags);
1139 template<
typename _ForwardIterator,
1140 typename _UniformRandomNumberGenerator>
1142 std::bernoulli_distribution::
1143 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1144 _UniformRandomNumberGenerator& __urng,
1145 const param_type& __p)
1147 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1148 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1150 auto __limit = __p.p() * (__aurng.max() - __aurng.min());
1153 *__f++ = (__aurng() - __aurng.min()) < __limit;
1156 template<
typename _CharT,
typename _Traits>
1159 const bernoulli_distribution& __x)
1161 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1163 const typename __ios_base::fmtflags __flags = __os.
flags();
1164 const _CharT __fill = __os.
fill();
1166 __os.
flags(__ios_base::scientific | __ios_base::left);
1172 __os.
flags(__flags);
1179 template<
typename _IntType>
1180 template<
typename _UniformRandomNumberGenerator>
1183 operator()(_UniformRandomNumberGenerator& __urng,
1184 const param_type& __param)
1188 const double __naf =
1191 const double __thr =
1193 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1198 __cand = std::floor(
std::log(1.0 - __aurng()) / __param._M_log_1_p);
1199 while (__cand >= __thr);
1201 return result_type(__cand + __naf);
1204 template<
typename _IntType>
1205 template<
typename _ForwardIterator,
1206 typename _UniformRandomNumberGenerator>
1210 _UniformRandomNumberGenerator& __urng,
1211 const param_type& __param)
1213 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1216 const double __naf =
1219 const double __thr =
1221 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1228 __cand = std::floor(
std::log(1.0 - __aurng())
1229 / __param._M_log_1_p);
1230 while (__cand >= __thr);
1232 *__f++ = __cand + __naf;
1236 template<
typename _IntType,
1237 typename _CharT,
typename _Traits>
1240 const geometric_distribution<_IntType>& __x)
1242 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1244 const typename __ios_base::fmtflags __flags = __os.
flags();
1245 const _CharT __fill = __os.
fill();
1247 __os.
flags(__ios_base::scientific | __ios_base::left);
1253 __os.
flags(__flags);
1259 template<
typename _IntType,
1260 typename _CharT,
typename _Traits>
1261 std::basic_istream<_CharT, _Traits>&
1266 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1268 const typename __ios_base::fmtflags __flags = __is.
flags();
1269 __is.
flags(__ios_base::skipws);
1273 __x.
param(param_type(__p));
1275 __is.
flags(__flags);
1280 template<
typename _IntType>
1281 template<
typename _UniformRandomNumberGenerator>
1282 typename negative_binomial_distribution<_IntType>::result_type
1284 operator()(_UniformRandomNumberGenerator& __urng)
1286 const double __y = _M_gd(__urng);
1290 return __poisson(__urng);
1293 template<
typename _IntType>
1294 template<
typename _UniformRandomNumberGenerator>
1297 operator()(_UniformRandomNumberGenerator& __urng,
1298 const param_type& __p)
1304 _M_gd(__urng, param_type(__p.k(), (1.0 - __p.p()) / __p.p()));
1307 return __poisson(__urng);
1310 template<
typename _IntType>
1311 template<
typename _ForwardIterator,
1312 typename _UniformRandomNumberGenerator>
1314 negative_binomial_distribution<_IntType>::
1315 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
1316 _UniformRandomNumberGenerator& __urng)
1318 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1321 const double __y = _M_gd(__urng);
1325 *__f++ = __poisson(__urng);
1329 template<
typename _IntType>
1330 template<
typename _ForwardIterator,
1331 typename _UniformRandomNumberGenerator>
1335 _UniformRandomNumberGenerator& __urng,
1336 const param_type& __p)
1338 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1339 typename std::gamma_distribution<result_type>::param_type
1340 __p2(__p.k(), (1.0 - __p.p()) / __p.p());
1344 const double __y = _M_gd(__urng, __p2);
1346 std::poisson_distribution<result_type> __poisson(__y);
1347 *__f++ = __poisson(__urng);
1351 template<
typename _IntType,
typename _CharT,
typename _Traits>
1352 std::basic_ostream<_CharT, _Traits>&
1353 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
1356 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1358 const typename __ios_base::fmtflags __flags = __os.
flags();
1359 const _CharT __fill = __os.
fill();
1361 const _CharT __space = __os.
widen(
' ');
1362 __os.
flags(__ios_base::scientific | __ios_base::left);
1366 __os << __x.k() << __space << __x.p()
1367 << __space << __x._M_gd;
1369 __os.
flags(__flags);
1375 template<
typename _IntType,
typename _CharT,
typename _Traits>
1376 std::basic_istream<_CharT, _Traits>&
1377 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1382 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1384 const typename __ios_base::fmtflags __flags = __is.
flags();
1385 __is.
flags(__ios_base::skipws);
1389 if (__is >> __k >> __p >> __x._M_gd)
1390 __x.param(param_type(__k, __p));
1392 __is.
flags(__flags);
1397 template<
typename _IntType>
1402#if _GLIBCXX_USE_C99_MATH_FUNCS
1405 const double __m = std::floor(_M_mean);
1407 _M_lfm = std::lgamma(__m + 1);
1410 const double __pi_4 = 0.7853981633974483096156608458198757L;
1414 const double __cx = 2 * __m + _M_d;
1419 _M_cb = 2 * __cx *
std::exp(-_M_d * _M_1cx * (1 + _M_d / 2))
1437 template<
typename _IntType>
1438 template<
typename _UniformRandomNumberGenerator>
1439 typename poisson_distribution<_IntType>::result_type
1441 operator()(_UniformRandomNumberGenerator& __urng,
1444 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1446#if _GLIBCXX_USE_C99_MATH_FUNCS
1447 if (__param.mean() >= 12)
1452 const double __naf =
1454 const double __thr =
1457 const double __m = std::floor(__param.mean());
1459 const double __spi_2 = 1.2533141373155002512078826424055226L;
1460 const double __c1 = __param._M_sm * __spi_2;
1461 const double __c2 = __param._M_c2b + __c1;
1462 const double __c3 = __c2 + 1;
1463 const double __c4 = __c3 + 1;
1465 const double __178 = 0.0128205128205128205128205128205128L;
1467 const double __e178 = 1.0129030479320018583185514777512983L;
1468 const double __c5 = __c4 + __e178;
1469 const double __c = __param._M_cb + __c5;
1470 const double __2cx = 2 * (2 * __m + __param._M_d);
1472 bool __reject =
true;
1475 const double __u = __c * __aurng();
1476 const double __e = -
std::log(1.0 - __aurng());
1482 const double __n = _M_nd(__urng);
1483 const double __y = -
std::abs(__n) * __param._M_sm - 1;
1484 __x = std::floor(__y);
1485 __w = -__n * __n / 2;
1489 else if (__u <= __c2)
1491 const double __n = _M_nd(__urng);
1492 const double __y = 1 +
std::abs(__n) * __param._M_scx;
1493 __x = std::ceil(__y);
1494 __w = __y * (2 - __y) * __param._M_1cx;
1495 if (__x > __param._M_d)
1498 else if (__u <= __c3)
1502 else if (__u <= __c4)
1504 else if (__u <= __c5)
1512 const double __v = -
std::log(1.0 - __aurng());
1513 const double __y = __param._M_d
1514 + __v * __2cx / __param._M_d;
1515 __x = std::ceil(__y);
1516 __w = -__param._M_d * __param._M_1cx * (1 + __y / 2);
1519 __reject = (__w - __e - __x * __param._M_lm_thr
1520 > __param._M_lfm - std::lgamma(__x + __m + 1));
1522 __reject |= __x + __m >= __thr;
1532 double __prod = 1.0;
1536 __prod *= __aurng();
1539 while (__prod > __param._M_lm_thr);
1545 template<
typename _IntType>
1546 template<
typename _ForwardIterator,
1547 typename _UniformRandomNumberGenerator>
1551 _UniformRandomNumberGenerator& __urng,
1552 const param_type& __param)
1554 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1560 template<
typename _IntType,
1561 typename _CharT,
typename _Traits>
1564 const poisson_distribution<_IntType>& __x)
1566 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1568 const typename __ios_base::fmtflags __flags = __os.
flags();
1569 const _CharT __fill = __os.
fill();
1571 const _CharT __space = __os.
widen(
' ');
1572 __os.
flags(__ios_base::scientific | __ios_base::left);
1576 __os << __x.mean() << __space << __x._M_nd;
1578 __os.
flags(__flags);
1584 template<
typename _IntType,
1585 typename _CharT,
typename _Traits>
1586 std::basic_istream<_CharT, _Traits>&
1587 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1588 poisson_distribution<_IntType>& __x)
1590 using param_type =
typename poisson_distribution<_IntType>::param_type;
1591 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1593 const typename __ios_base::fmtflags __flags = __is.
flags();
1594 __is.
flags(__ios_base::skipws);
1597 if (__is >> __mean >> __x._M_nd)
1600 __is.
flags(__flags);
1605 template<
typename _IntType>
1607 binomial_distribution<_IntType>::param_type::
1610 const double __p12 = _M_p <= 0.5 ? _M_p : 1.0 - _M_p;
1614#if _GLIBCXX_USE_C99_MATH_FUNCS
1615 if (_M_t * __p12 >= 8)
1618 const double __np = std::floor(_M_t * __p12);
1619 const double __pa = __np / _M_t;
1620 const double __1p = 1 - __pa;
1622 const double __pi_4 = 0.7853981633974483096156608458198757L;
1623 const double __d1x =
1625 / (81 * __pi_4 * __1p)));
1627 const double __d2x =
1629 / (__pi_4 * __pa)));
1633 const double __spi_2 = 1.2533141373155002512078826424055226L;
1634 _M_s1 =
std::sqrt(__np * __1p) * (1 + _M_d1 / (4 * __np));
1635 _M_s2 =
std::sqrt(__np * __1p) * (1 + _M_d2 / (4 * (_M_t * __1p)));
1636 _M_c = 2 * _M_d1 / __np;
1637 _M_a1 =
std::exp(_M_c) * _M_s1 * __spi_2;
1638 const double __a12 = _M_a1 + _M_s2 * __spi_2;
1639 const double __s1s = _M_s1 * _M_s1;
1640 _M_a123 = __a12 + (
std::exp(_M_d1 / (_M_t * __1p))
1642 *
std::exp(-_M_d1 * _M_d1 / (2 * __s1s)));
1643 const double __s2s = _M_s2 * _M_s2;
1644 _M_s = (_M_a123 + 2 * __s2s / _M_d2
1645 *
std::exp(-_M_d2 * _M_d2 / (2 * __s2s)));
1646 _M_lf = (std::lgamma(__np + 1)
1647 + std::lgamma(_M_t - __np + 1));
1650 _M_q = -
std::log(1 - (__p12 - __pa) / __1p);
1657 template<
typename _IntType>
1658 template<
typename _UniformRandomNumberGenerator>
1660 binomial_distribution<_IntType>::
1661 _M_waiting(_UniformRandomNumberGenerator& __urng,
1662 _IntType __t,
double __q)
1666 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1673 const double __e = -
std::log(1.0 - __aurng());
1674 __sum += __e / (__t - __x);
1677 while (__sum <= __q);
1692 template<
typename _IntType>
1693 template<
typename _UniformRandomNumberGenerator>
1696 operator()(_UniformRandomNumberGenerator& __urng,
1700 const _IntType __t = __param.t();
1701 const double __p = __param.p();
1702 const double __p12 = __p <= 0.5 ? __p : 1.0 - __p;
1703 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
1706#if _GLIBCXX_USE_C99_MATH_FUNCS
1707 if (!__param._M_easy)
1712 const double __naf =
1714 const double __thr =
1717 const double __np = std::floor(__t * __p12);
1720 const double __spi_2 = 1.2533141373155002512078826424055226L;
1721 const double __a1 = __param._M_a1;
1722 const double __a12 = __a1 + __param._M_s2 * __spi_2;
1723 const double __a123 = __param._M_a123;
1724 const double __s1s = __param._M_s1 * __param._M_s1;
1725 const double __s2s = __param._M_s2 * __param._M_s2;
1730 const double __u = __param._M_s * __aurng();
1736 const double __n = _M_nd(__urng);
1737 const double __y = __param._M_s1 *
std::abs(__n);
1738 __reject = __y >= __param._M_d1;
1741 const double __e = -
std::log(1.0 - __aurng());
1742 __x = std::floor(__y);
1743 __v = -__e - __n * __n / 2 + __param._M_c;
1746 else if (__u <= __a12)
1748 const double __n = _M_nd(__urng);
1749 const double __y = __param._M_s2 *
std::abs(__n);
1750 __reject = __y >= __param._M_d2;
1753 const double __e = -
std::log(1.0 - __aurng());
1754 __x = std::floor(-__y);
1755 __v = -__e - __n * __n / 2;
1758 else if (__u <= __a123)
1760 const double __e1 = -
std::log(1.0 - __aurng());
1761 const double __e2 = -
std::log(1.0 - __aurng());
1763 const double __y = __param._M_d1
1764 + 2 * __s1s * __e1 / __param._M_d1;
1765 __x = std::floor(__y);
1766 __v = (-__e2 + __param._M_d1 * (1 / (__t - __np)
1767 -__y / (2 * __s1s)));
1772 const double __e1 = -
std::log(1.0 - __aurng());
1773 const double __e2 = -
std::log(1.0 - __aurng());
1775 const double __y = __param._M_d2
1776 + 2 * __s2s * __e1 / __param._M_d2;
1777 __x = std::floor(-__y);
1778 __v = -__e2 - __param._M_d2 * __y / (2 * __s2s);
1782 __reject = __reject || __x < -__np || __x > __t - __np;
1785 const double __lfx =
1786 std::lgamma(__np + __x + 1)
1787 + std::lgamma(__t - (__np + __x) + 1);
1788 __reject = __v > __param._M_lf - __lfx
1789 + __x * __param._M_lp1p;
1792 __reject |= __x + __np >= __thr;
1796 __x += __np + __naf;
1798 const _IntType __z = _M_waiting(__urng, __t - _IntType(__x),
1800 __ret = _IntType(__x) + __z;
1804 __ret = _M_waiting(__urng, __t, __param._M_q);
1807 __ret = __t - __ret;
1811 template<
typename _IntType>
1812 template<
typename _ForwardIterator,
1813 typename _UniformRandomNumberGenerator>
1817 _UniformRandomNumberGenerator& __urng,
1818 const param_type& __param)
1820 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1826 template<
typename _IntType,
1827 typename _CharT,
typename _Traits>
1830 const binomial_distribution<_IntType>& __x)
1832 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1834 const typename __ios_base::fmtflags __flags = __os.
flags();
1835 const _CharT __fill = __os.
fill();
1837 const _CharT __space = __os.
widen(
' ');
1838 __os.
flags(__ios_base::scientific | __ios_base::left);
1842 __os << __x.t() << __space << __x.p()
1843 << __space << __x._M_nd;
1845 __os.
flags(__flags);
1851 template<
typename _IntType,
1852 typename _CharT,
typename _Traits>
1853 std::basic_istream<_CharT, _Traits>&
1854 operator>>(std::basic_istream<_CharT, _Traits>& __is,
1855 binomial_distribution<_IntType>& __x)
1857 using param_type =
typename binomial_distribution<_IntType>::param_type;
1858 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1860 const typename __ios_base::fmtflags __flags = __is.
flags();
1861 __is.
flags(__ios_base::dec | __ios_base::skipws);
1865 if (__is >> __t >> __p >> __x._M_nd)
1868 __is.
flags(__flags);
1873 template<
typename _RealType>
1874 template<
typename _ForwardIterator,
1875 typename _UniformRandomNumberGenerator>
1879 _UniformRandomNumberGenerator& __urng,
1880 const param_type& __p)
1882 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1883 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1889 template<
typename _RealType,
typename _CharT,
typename _Traits>
1892 const exponential_distribution<_RealType>& __x)
1894 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
1896 const typename __ios_base::fmtflags __flags = __os.
flags();
1897 const _CharT __fill = __os.
fill();
1899 __os.
flags(__ios_base::scientific | __ios_base::left);
1903 __os << __x.lambda();
1905 __os.
flags(__flags);
1911 template<
typename _RealType,
typename _CharT,
typename _Traits>
1912 std::basic_istream<_CharT, _Traits>&
1918 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
1920 const typename __ios_base::fmtflags __flags = __is.
flags();
1921 __is.
flags(__ios_base::dec | __ios_base::skipws);
1924 if (__is >> __lambda)
1925 __x.
param(param_type(__lambda));
1927 __is.
flags(__flags);
1938 template<
typename _RealType>
1939 template<
typename _UniformRandomNumberGenerator>
1942 operator()(_UniformRandomNumberGenerator& __urng,
1946 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
1949 if (_M_saved_available)
1951 _M_saved_available =
false;
1961 __r2 = __x * __x + __y * __y;
1963 while (__r2 > 1.0 || __r2 == 0.0);
1966 _M_saved = __x * __mult;
1967 _M_saved_available =
true;
1968 __ret = __y * __mult;
1971 __ret = __ret * __param.stddev() + __param.mean();
1975 template<
typename _RealType>
1976 template<
typename _ForwardIterator,
1977 typename _UniformRandomNumberGenerator>
1981 _UniformRandomNumberGenerator& __urng,
1982 const param_type& __param)
1984 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1989 if (_M_saved_available)
1991 _M_saved_available =
false;
1992 *__f++ = _M_saved * __param.stddev() + __param.mean();
1998 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2001 while (__f + 1 < __t)
2003 result_type __x, __y, __r2;
2008 __r2 = __x * __x + __y * __y;
2010 while (__r2 > 1.0 || __r2 == 0.0);
2013 *__f++ = __y * __mult * __param.stddev() + __param.mean();
2014 *__f++ = __x * __mult * __param.stddev() + __param.mean();
2024 __r2 = __x * __x + __y * __y;
2026 while (__r2 > 1.0 || __r2 == 0.0);
2029 _M_saved = __x * __mult;
2030 _M_saved_available =
true;
2031 *__f = __y * __mult * __param.stddev() + __param.mean();
2035 template<
typename _RealType>
2037 operator==(
const std::normal_distribution<_RealType>& __d1,
2038 const std::normal_distribution<_RealType>& __d2)
2040 if (__d1._M_param == __d2._M_param
2041 && __d1._M_saved_available == __d2._M_saved_available)
2042 return __d1._M_saved_available ? __d1._M_saved == __d2._M_saved :
true;
2047 template<
typename _RealType,
typename _CharT,
typename _Traits>
2048 std::basic_ostream<_CharT, _Traits>&
2049 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2050 const normal_distribution<_RealType>& __x)
2052 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2054 const typename __ios_base::fmtflags __flags = __os.
flags();
2055 const _CharT __fill = __os.
fill();
2057 const _CharT __space = __os.
widen(
' ');
2058 __os.
flags(__ios_base::scientific | __ios_base::left);
2062 __os << __x.mean() << __space << __x.stddev()
2063 << __space << __x._M_saved_available;
2064 if (__x._M_saved_available)
2065 __os << __space << __x._M_saved;
2067 __os.
flags(__flags);
2073 template<
typename _RealType,
typename _CharT,
typename _Traits>
2074 std::basic_istream<_CharT, _Traits>&
2075 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2076 normal_distribution<_RealType>& __x)
2078 using param_type =
typename normal_distribution<_RealType>::param_type;
2079 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2081 const typename __ios_base::fmtflags __flags = __is.
flags();
2082 __is.
flags(__ios_base::dec | __ios_base::skipws);
2084 double __mean, __stddev;
2086 if (__is >> __mean >> __stddev >> __saved_avail)
2088 if (!__saved_avail || (__is >> __x._M_saved))
2090 __x._M_saved_available = __saved_avail;
2095 __is.
flags(__flags);
2100 template<
typename _RealType>
2101 template<
typename _ForwardIterator,
2102 typename _UniformRandomNumberGenerator>
2104 lognormal_distribution<_RealType>::
2105 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2106 _UniformRandomNumberGenerator& __urng,
2109 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2111 *__f++ =
std::exp(__p.s() * _M_nd(__urng) + __p.m());
2114 template<
typename _RealType,
typename _CharT,
typename _Traits>
2115 std::basic_ostream<_CharT, _Traits>&
2116 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2117 const lognormal_distribution<_RealType>& __x)
2119 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2121 const typename __ios_base::fmtflags __flags = __os.
flags();
2122 const _CharT __fill = __os.
fill();
2124 const _CharT __space = __os.
widen(
' ');
2125 __os.
flags(__ios_base::scientific | __ios_base::left);
2129 __os << __x.m() << __space << __x.s()
2130 << __space << __x._M_nd;
2132 __os.
flags(__flags);
2138 template<
typename _RealType,
typename _CharT,
typename _Traits>
2139 std::basic_istream<_CharT, _Traits>&
2140 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2141 lognormal_distribution<_RealType>& __x)
2144 =
typename lognormal_distribution<_RealType>::param_type;
2145 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2147 const typename __ios_base::fmtflags __flags = __is.
flags();
2148 __is.
flags(__ios_base::dec | __ios_base::skipws);
2151 if (__is >> __m >> __s >> __x._M_nd)
2154 __is.
flags(__flags);
2158 template<
typename _RealType>
2159 template<
typename _ForwardIterator,
2160 typename _UniformRandomNumberGenerator>
2162 std::chi_squared_distribution<_RealType>::
2163 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2164 _UniformRandomNumberGenerator& __urng)
2166 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2168 *__f++ = 2 * _M_gd(__urng);
2171 template<
typename _RealType>
2172 template<
typename _ForwardIterator,
2173 typename _UniformRandomNumberGenerator>
2175 std::chi_squared_distribution<_RealType>::
2176 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2177 _UniformRandomNumberGenerator& __urng,
2179 std::gamma_distribution<result_type>::param_type& __p)
2181 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2183 *__f++ = 2 * _M_gd(__urng, __p);
2186 template<
typename _RealType,
typename _CharT,
typename _Traits>
2187 std::basic_ostream<_CharT, _Traits>&
2188 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2189 const chi_squared_distribution<_RealType>& __x)
2191 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2193 const typename __ios_base::fmtflags __flags = __os.
flags();
2194 const _CharT __fill = __os.
fill();
2196 const _CharT __space = __os.
widen(
' ');
2197 __os.
flags(__ios_base::scientific | __ios_base::left);
2201 __os << __x.n() << __space << __x._M_gd;
2203 __os.
flags(__flags);
2209 template<
typename _RealType,
typename _CharT,
typename _Traits>
2210 std::basic_istream<_CharT, _Traits>&
2211 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2212 chi_squared_distribution<_RealType>& __x)
2215 =
typename chi_squared_distribution<_RealType>::param_type;
2216 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2218 const typename __ios_base::fmtflags __flags = __is.
flags();
2219 __is.
flags(__ios_base::dec | __ios_base::skipws);
2222 if (__is >> __n >> __x._M_gd)
2225 __is.
flags(__flags);
2230 template<
typename _RealType>
2231 template<
typename _UniformRandomNumberGenerator>
2234 operator()(_UniformRandomNumberGenerator& __urng,
2237 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2244 const _RealType __pi = 3.1415926535897932384626433832795029L;
2245 return __p.a() + __p.b() *
std::tan(__pi * __u);
2248 template<
typename _RealType>
2249 template<
typename _ForwardIterator,
2250 typename _UniformRandomNumberGenerator>
2254 _UniformRandomNumberGenerator& __urng,
2255 const param_type& __p)
2257 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2258 const _RealType __pi = 3.1415926535897932384626433832795029L;
2259 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2268 *__f++ = __p.a() + __p.b() *
std::tan(__pi * __u);
2272 template<
typename _RealType,
typename _CharT,
typename _Traits>
2275 const cauchy_distribution<_RealType>& __x)
2277 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2279 const typename __ios_base::fmtflags __flags = __os.
flags();
2280 const _CharT __fill = __os.
fill();
2282 const _CharT __space = __os.
widen(
' ');
2283 __os.
flags(__ios_base::scientific | __ios_base::left);
2287 __os << __x.a() << __space << __x.b();
2289 __os.
flags(__flags);
2295 template<
typename _RealType,
typename _CharT,
typename _Traits>
2296 std::basic_istream<_CharT, _Traits>&
2301 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2303 const typename __ios_base::fmtflags __flags = __is.
flags();
2304 __is.
flags(__ios_base::dec | __ios_base::skipws);
2307 if (__is >> __a >> __b)
2308 __x.
param(param_type(__a, __b));
2310 __is.
flags(__flags);
2315 template<
typename _RealType>
2316 template<
typename _ForwardIterator,
2317 typename _UniformRandomNumberGenerator>
2321 _UniformRandomNumberGenerator& __urng)
2323 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2325 *__f++ = ((_M_gd_x(__urng) * n()) / (_M_gd_y(__urng) * m()));
2328 template<
typename _RealType>
2329 template<
typename _ForwardIterator,
2330 typename _UniformRandomNumberGenerator>
2332 std::fisher_f_distribution<_RealType>::
2333 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2334 _UniformRandomNumberGenerator& __urng,
2337 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2338 typedef typename std::gamma_distribution<result_type>::param_type
2343 *__f++ = ((_M_gd_x(__urng, __p1) * n())
2344 / (_M_gd_y(__urng, __p2) * m()));
2347 template<
typename _RealType,
typename _CharT,
typename _Traits>
2348 std::basic_ostream<_CharT, _Traits>&
2349 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2350 const fisher_f_distribution<_RealType>& __x)
2352 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2354 const typename __ios_base::fmtflags __flags = __os.
flags();
2355 const _CharT __fill = __os.
fill();
2357 const _CharT __space = __os.
widen(
' ');
2358 __os.
flags(__ios_base::scientific | __ios_base::left);
2362 __os << __x.m() << __space << __x.n()
2363 << __space << __x._M_gd_x << __space << __x._M_gd_y;
2365 __os.
flags(__flags);
2371 template<
typename _RealType,
typename _CharT,
typename _Traits>
2372 std::basic_istream<_CharT, _Traits>&
2373 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2374 fisher_f_distribution<_RealType>& __x)
2377 =
typename fisher_f_distribution<_RealType>::param_type;
2378 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2380 const typename __ios_base::fmtflags __flags = __is.
flags();
2381 __is.
flags(__ios_base::dec | __ios_base::skipws);
2384 if (__is >> __m >> __n >> __x._M_gd_x >> __x._M_gd_y)
2387 __is.
flags(__flags);
2392 template<
typename _RealType>
2393 template<
typename _ForwardIterator,
2394 typename _UniformRandomNumberGenerator>
2396 std::student_t_distribution<_RealType>::
2397 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2398 _UniformRandomNumberGenerator& __urng)
2400 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2402 *__f++ = _M_nd(__urng) *
std::sqrt(n() / _M_gd(__urng));
2405 template<
typename _RealType>
2406 template<
typename _ForwardIterator,
2407 typename _UniformRandomNumberGenerator>
2409 std::student_t_distribution<_RealType>::
2410 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2411 _UniformRandomNumberGenerator& __urng,
2414 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2415 typename std::gamma_distribution<result_type>::param_type
2416 __p2(__p.n() / 2, 2);
2418 *__f++ = _M_nd(__urng) *
std::sqrt(__p.n() / _M_gd(__urng, __p2));
2421 template<
typename _RealType,
typename _CharT,
typename _Traits>
2422 std::basic_ostream<_CharT, _Traits>&
2423 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2424 const student_t_distribution<_RealType>& __x)
2426 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2428 const typename __ios_base::fmtflags __flags = __os.
flags();
2429 const _CharT __fill = __os.
fill();
2431 const _CharT __space = __os.
widen(
' ');
2432 __os.
flags(__ios_base::scientific | __ios_base::left);
2436 __os << __x.n() << __space << __x._M_nd << __space << __x._M_gd;
2438 __os.
flags(__flags);
2444 template<
typename _RealType,
typename _CharT,
typename _Traits>
2445 std::basic_istream<_CharT, _Traits>&
2446 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2447 student_t_distribution<_RealType>& __x)
2450 =
typename student_t_distribution<_RealType>::param_type;
2451 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2453 const typename __ios_base::fmtflags __flags = __is.
flags();
2454 __is.
flags(__ios_base::dec | __ios_base::skipws);
2457 if (__is >> __n >> __x._M_nd >> __x._M_gd)
2460 __is.
flags(__flags);
2465 template<
typename _RealType>
2467 gamma_distribution<_RealType>::param_type::
2470 _M_malpha = _M_alpha < 1.0 ? _M_alpha + _RealType(1.0) : _M_alpha;
2472 const _RealType __a1 = _M_malpha - _RealType(1.0) / _RealType(3.0);
2473 _M_a2 = _RealType(1.0) /
std::sqrt(_RealType(9.0) * __a1);
2481 template<
typename _RealType>
2482 template<
typename _UniformRandomNumberGenerator>
2485 operator()(_UniformRandomNumberGenerator& __urng,
2488 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2493 - _RealType(1.0) / _RealType(3.0));
2499 __n = _M_nd(__urng);
2504 __v = __v * __v * __v;
2507 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2508 && (
std::log(__u) > (0.5 * __n * __n + __a1
2511 if (__param.alpha() == __param._M_malpha)
2512 return __a1 * __v * __param.beta();
2520 * __a1 * __v * __param.beta());
2524 template<
typename _RealType>
2525 template<
typename _ForwardIterator,
2526 typename _UniformRandomNumberGenerator>
2530 _UniformRandomNumberGenerator& __urng,
2531 const param_type& __param)
2533 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2534 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2537 result_type __u, __v, __n;
2538 const result_type __a1 = (__param._M_malpha
2539 - _RealType(1.0) / _RealType(3.0));
2541 if (__param.alpha() == __param._M_malpha)
2548 __n = _M_nd(__urng);
2553 __v = __v * __v * __v;
2556 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2557 && (
std::log(__u) > (0.5 * __n * __n + __a1
2560 *__f++ = __a1 * __v * __param.beta();
2569 __n = _M_nd(__urng);
2574 __v = __v * __v * __v;
2577 while (__u >
result_type(1.0) - 0.0331 * __n * __n * __n * __n
2578 && (
std::log(__u) > (0.5 * __n * __n + __a1
2586 * __a1 * __v * __param.beta());
2590 template<
typename _RealType,
typename _CharT,
typename _Traits>
2591 std::basic_ostream<_CharT, _Traits>&
2592 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
2593 const gamma_distribution<_RealType>& __x)
2595 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2597 const typename __ios_base::fmtflags __flags = __os.
flags();
2598 const _CharT __fill = __os.
fill();
2600 const _CharT __space = __os.
widen(
' ');
2601 __os.
flags(__ios_base::scientific | __ios_base::left);
2605 __os << __x.alpha() << __space << __x.beta()
2606 << __space << __x._M_nd;
2608 __os.
flags(__flags);
2614 template<
typename _RealType,
typename _CharT,
typename _Traits>
2615 std::basic_istream<_CharT, _Traits>&
2616 operator>>(std::basic_istream<_CharT, _Traits>& __is,
2617 gamma_distribution<_RealType>& __x)
2619 using param_type =
typename gamma_distribution<_RealType>::param_type;
2620 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2622 const typename __ios_base::fmtflags __flags = __is.
flags();
2623 __is.
flags(__ios_base::dec | __ios_base::skipws);
2625 _RealType __alpha_val, __beta_val;
2626 if (__is >> __alpha_val >> __beta_val >> __x._M_nd)
2627 __x.param(
param_type(__alpha_val, __beta_val));
2629 __is.
flags(__flags);
2634 template<
typename _RealType>
2635 template<
typename _UniformRandomNumberGenerator>
2638 operator()(_UniformRandomNumberGenerator& __urng,
2641 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2647 template<
typename _RealType>
2648 template<
typename _ForwardIterator,
2649 typename _UniformRandomNumberGenerator>
2653 _UniformRandomNumberGenerator& __urng,
2654 const param_type& __p)
2656 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2657 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2666 template<
typename _RealType,
typename _CharT,
typename _Traits>
2669 const weibull_distribution<_RealType>& __x)
2671 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2673 const typename __ios_base::fmtflags __flags = __os.
flags();
2674 const _CharT __fill = __os.
fill();
2676 const _CharT __space = __os.
widen(
' ');
2677 __os.
flags(__ios_base::scientific | __ios_base::left);
2681 __os << __x.a() << __space << __x.b();
2683 __os.
flags(__flags);
2689 template<
typename _RealType,
typename _CharT,
typename _Traits>
2690 std::basic_istream<_CharT, _Traits>&
2695 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2697 const typename __ios_base::fmtflags __flags = __is.
flags();
2698 __is.
flags(__ios_base::dec | __ios_base::skipws);
2701 if (__is >> __a >> __b)
2702 __x.
param(param_type(__a, __b));
2704 __is.
flags(__flags);
2709 template<
typename _RealType>
2710 template<
typename _UniformRandomNumberGenerator>
2713 operator()(_UniformRandomNumberGenerator& __urng,
2714 const param_type& __p)
2716 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2722 template<
typename _RealType>
2723 template<
typename _ForwardIterator,
2724 typename _UniformRandomNumberGenerator>
2728 _UniformRandomNumberGenerator& __urng,
2729 const param_type& __p)
2731 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2732 __detail::_Adaptor<_UniformRandomNumberGenerator, result_type>
2740 template<
typename _RealType,
typename _CharT,
typename _Traits>
2743 const extreme_value_distribution<_RealType>& __x)
2745 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2747 const typename __ios_base::fmtflags __flags = __os.
flags();
2748 const _CharT __fill = __os.
fill();
2750 const _CharT __space = __os.
widen(
' ');
2751 __os.
flags(__ios_base::scientific | __ios_base::left);
2755 __os << __x.a() << __space << __x.b();
2757 __os.
flags(__flags);
2763 template<
typename _RealType,
typename _CharT,
typename _Traits>
2764 std::basic_istream<_CharT, _Traits>&
2770 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2772 const typename __ios_base::fmtflags __flags = __is.
flags();
2773 __is.
flags(__ios_base::dec | __ios_base::skipws);
2776 if (__is >> __a >> __b)
2777 __x.
param(param_type(__a, __b));
2779 __is.
flags(__flags);
2784 template<
typename _IntType>
2786 discrete_distribution<_IntType>::param_type::
2789 if (_M_prob.size() < 2)
2796 _M_prob.end(), 0.0);
2797 __glibcxx_assert(__sum > 0);
2799 __detail::__normalize(_M_prob.begin(), _M_prob.end(), _M_prob.begin(),
2802 _M_cp.reserve(_M_prob.size());
2806 _M_cp[_M_cp.size() - 1] = 1.0;
2809 template<
typename _IntType>
2810 template<
typename _Func>
2811 discrete_distribution<_IntType>::param_type::
2812 param_type(
size_t __nw,
double __xmin,
double __xmax, _Func __fw)
2813 : _M_prob(), _M_cp()
2815 const size_t __n = __nw == 0 ? 1 : __nw;
2816 const double __delta = (__xmax - __xmin) / __n;
2818 _M_prob.reserve(__n);
2819 for (
size_t __k = 0; __k < __nw; ++__k)
2820 _M_prob.push_back(__fw(__xmin + __k * __delta + 0.5 * __delta));
2825 template<
typename _IntType>
2826 template<
typename _UniformRandomNumberGenerator>
2827 typename discrete_distribution<_IntType>::result_type
2828 discrete_distribution<_IntType>::
2829 operator()(_UniformRandomNumberGenerator& __urng,
2830 const param_type& __param)
2832 if (__param._M_cp.empty())
2833 return result_type(0);
2835 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2838 const double __p = __aurng();
2839 auto __pos = std::lower_bound(__param._M_cp.begin(),
2840 __param._M_cp.end(), __p);
2842 return __pos - __param._M_cp.begin();
2845 template<
typename _IntType>
2846 template<
typename _ForwardIterator,
2847 typename _UniformRandomNumberGenerator>
2849 discrete_distribution<_IntType>::
2850 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
2851 _UniformRandomNumberGenerator& __urng,
2852 const param_type& __param)
2854 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
2856 if (__param._M_cp.empty())
2859 *__f++ = result_type(0);
2863 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
2868 const double __p = __aurng();
2869 auto __pos = std::lower_bound(__param._M_cp.begin(),
2870 __param._M_cp.end(), __p);
2872 *__f++ = __pos - __param._M_cp.begin();
2876 template<
typename _IntType,
typename _CharT,
typename _Traits>
2879 const discrete_distribution<_IntType>& __x)
2881 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
2883 const typename __ios_base::fmtflags __flags = __os.
flags();
2884 const _CharT __fill = __os.
fill();
2886 const _CharT __space = __os.
widen(
' ');
2887 __os.
flags(__ios_base::scientific | __ios_base::left);
2892 __os << __prob.
size();
2893 for (
auto __dit = __prob.
begin(); __dit != __prob.
end(); ++__dit)
2894 __os << __space << *__dit;
2896 __os.
flags(__flags);
2904 template<
typename _ValT,
typename _CharT,
typename _Traits>
2905 basic_istream<_CharT, _Traits>&
2906 __extract_params(basic_istream<_CharT, _Traits>& __is,
2907 vector<_ValT>& __vals,
size_t __n)
2909 __vals.reserve(__n);
2914 __vals.push_back(__val);
2922 template<
typename _IntType,
typename _CharT,
typename _Traits>
2925 discrete_distribution<_IntType>& __x)
2927 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
2929 const typename __ios_base::fmtflags __flags = __is.
flags();
2930 __is.
flags(__ios_base::dec | __ios_base::skipws);
2936 if (__detail::__extract_params(__is, __prob_vec, __n))
2937 __x.param({__prob_vec.
begin(), __prob_vec.
end()});
2940 __is.
flags(__flags);
2945 template<
typename _RealType>
2947 piecewise_constant_distribution<_RealType>::param_type::
2952 __glibcxx_assert(__sum > 0);
2954 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
2957 _CalcType __psum(0);
2958 _M_cp.reserve(_M_den.size());
2959 for (_CalcType __den : _M_den)
2960 _M_cp.push_back(__psum += __den);
2963 _M_cp[_M_cp.size() - 1] = _CalcType(1);
2965 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2966 _M_den[__k] = _CalcType(_CalcType(_M_den[__k])
2967 / (_M_int[__k + 1] - _M_int[__k]));
2970 template<
typename _RealType>
2972 piecewise_constant_distribution<_RealType>::param_type::
2973 _M_initialize2(
const _RealType* __ints, _CalcType __den)
2975 if (__ints[0] == _RealType(0) && __ints[1] == _RealType(1))
2979 _M_int.push_back(__ints[0]);
2980 _M_int.push_back(__ints[1]);
2983 _M_den.push_back(__den);
2989 template<
typename _InputIterator,
typename _RealType>
2991 __load_first2(_InputIterator& __first, _InputIterator __last,
2994 if (__first == __last)
2999 if (__first == __last)
3010 template<
typename _RealType>
3011 template<
typename _InputIteratorB,
typename _InputIteratorW>
3012 piecewise_constant_distribution<_RealType>::param_type::
3013 param_type(_InputIteratorB __bbegin,
3014 _InputIteratorB __bend,
3015 _InputIteratorW __wbegin)
3016 : _M_int(), _M_den(), _M_cp()
3018 _RealType __ints[2];
3019 if (!__detail::__load_first2(__bbegin, __bend, __ints))
3022 if (__bbegin == __bend)
3024 _M_initialize2(__ints, *__wbegin);
3028#if __glibcxx_concepts
3029 if constexpr (sized_sentinel_for<_InputIteratorB, _InputIteratorB>
3030 || forward_iterator<_InputIteratorB>)
3031 _M_int.reserve(2 +
size_t(ranges::distance(__bbegin, __bend)));
3033#pragma GCC diagnostic push
3034#pragma GCC diagnostic ignored "-Wc++17-extensions"
3035 if constexpr (is_convertible<__iter_category_t<_InputIteratorB>,
3037 _M_int.reserve(2 +
size_t(
std::distance(__bbegin, __bend)));
3038#pragma GCC diagnostic pop
3041 _M_int.push_back(__ints[0]);
3042 _M_int.push_back(__ints[1]);
3043 for (; __bbegin != __bend; ++__bbegin)
3044 _M_int.push_back(*__bbegin);
3048 _M_den.reserve(_M_int.size() - 1);
3049 for (
size_t __k = 0; __k < _M_int.size() - 1; (void)++__k, ++__wbegin)
3050 _M_den.push_back(_CalcType(*__wbegin));
3055 template<
typename _RealType>
3056 template<
typename _Func>
3057 piecewise_constant_distribution<_RealType>::param_type::
3058 param_type(initializer_list<_RealType> __bl, _Func __fw)
3059 : _M_int(), _M_den(), _M_cp()
3061 if (__bl.size() < 2)
3066 auto __cfw = [&__fw](_RealType __n, _RealType __p)
3068#ifdef _GLIBCXX_USE_OLD_PIECEWISE_DISTRIBUTIONS
3069 return __fw(0.5 * (__n + __p));
3071 return _RealType(__fw(_RealType(0.5) * (__n + __p)));
3075 if (__bl.size() == 2)
3077 const _RealType *__ints = __bl.begin();
3078 _CalcType __den = __cfw(__ints[1], __ints[0]);
3079 _M_initialize2(__ints, __den);
3084 _M_den.reserve(_M_int.size() - 1);
3085 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3086 _M_den.push_back(__cfw(_M_int[__k + 1], _M_int[__k]));
3091 template<
typename _RealType>
3092 template<
typename _Func>
3093 piecewise_constant_distribution<_RealType>::param_type::
3094 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3095 : _M_int(), _M_den(), _M_cp()
3097 const size_t __n = __nw == 0 ? 1 : __nw;
3098 const _RealType __delta = (__xmax - __xmin) / __n;
3099 auto __cfw = [&__fw, __delta](_RealType __v)
3101#ifdef _GLIBCXX_USE_OLD_PIECEWISE_DISTRIBUTIONS
3102 return __fw(__v + 0.5 * __delta);
3104 return _RealType(__fw(__v + _RealType(0.5) * __delta));
3110 _RealType __ints[2] = { __xmin, __xmin + __delta };
3111 _CalcType __den = __cfw(__xmin);
3112 _M_initialize2(__ints, __den);
3116 _M_int.reserve(__n + 1);
3117 for (
size_t __k = 0; __k <= __nw; ++__k)
3118 _M_int.push_back(__xmin + __k * __delta);
3120 _M_den.reserve(__n);
3121 for (
size_t __k = 0; __k < __nw; ++__k)
3122 _M_den.push_back(__cfw(_M_int[__k]));
3127 template<
typename _RealType>
3128 template<
typename _AdaptedUniformRandomNumberGenerator>
3129 typename piecewise_constant_distribution<_RealType>::result_type
3130 piecewise_constant_distribution<_RealType>::
3131 __generate_one(_AdaptedUniformRandomNumberGenerator& __aurng,
3132 const param_type& __param)
3134 const _CalcType __p = __aurng();
3135 auto __pos = std::lower_bound(__param._M_cp.begin(),
3136 __param._M_cp.end(), __p);
3137 const size_t __i = __pos - __param._M_cp.begin();
3138 const _CalcType __pref = __i > 0 ? __param._M_cp[__i - 1] : _CalcType(0);
3139 return __param._M_int[__i] + (__p - __pref) / _CalcType(__param._M_den[__i]);
3142 template<
typename _RealType>
3143 template<
typename _UniformRandomNumberGenerator>
3144 typename piecewise_constant_distribution<_RealType>::result_type
3145 piecewise_constant_distribution<_RealType>::
3146 operator()(_UniformRandomNumberGenerator& __urng,
3147 const param_type& __param)
3149 __detail::_Adaptor<_UniformRandomNumberGenerator, _CalcType>
3152 if (__param._M_cp.empty())
3155 return __generate_one(__aurng, __param);
3158 template<
typename _RealType>
3159 template<
typename _ForwardIterator,
3160 typename _UniformRandomNumberGenerator>
3162 piecewise_constant_distribution<_RealType>::
3163 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3164 _UniformRandomNumberGenerator& __urng,
3165 const param_type& __param)
3167 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3168 __detail::_Adaptor<_UniformRandomNumberGenerator, _CalcType>
3171 if (__param._M_cp.empty())
3176 *__f++ = __generate_one(__urng, __param);
3179 template<
typename _RealType,
typename _CharT,
typename _Traits>
3182 const piecewise_constant_distribution<_RealType>& __x)
3184 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
3186 const typename __ios_base::fmtflags __flags = __os.
flags();
3187 const _CharT __fill = __os.
fill();
3189 const _CharT __space = __os.
widen(
' ');
3190 __os.
flags(__ios_base::scientific | __ios_base::left);
3194 const auto& __int = __x._M_param._M_int;
3197 << __space << _RealType(0) << __space << _RealType(1)
3198 << __space << _RealType(1);
3201 __os << __int.size() - 1;
3202 for (
auto __xv : __int)
3203 __os << __space << __xv;
3204 for (
auto __dv : __x._M_param._M_den)
3205 __os << __space << __dv;
3208 __os.
flags(__flags);
3214 template<
typename _RealType,
typename _CharT,
typename _Traits>
3217 piecewise_constant_distribution<_RealType>& __x)
3219 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3221 =
typename piecewise_constant_distribution<_RealType>::_StorageType;
3223 const typename __ios_base::fmtflags __flags = __is.
flags();
3224 __is.
flags(__ios_base::dec | __ios_base::skipws);
3230 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3233 if (__detail::__extract_params(__is, __den_vec, __n))
3235 __x.param({ __int_vec.
begin(), __int_vec.
end(),
3236 __den_vec.
begin() });
3241 __is.
flags(__flags);
3246 template<
typename _RealType>
3248 piecewise_linear_distribution<_RealType>::param_type::
3251 _CalcType __sum = 0.0;
3252 _M_cp.reserve(_M_int.size() - 1);
3253 _M_m.reserve(_M_int.size() - 1);
3254 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3256 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
3257 __sum += _CalcType(0.5)
3258 * (_CalcType(_M_den[__k + 1]) + _CalcType(_M_den[__k]))
3260 _M_cp.push_back(__sum);
3262 (_CalcType(_M_den[__k + 1]) - _CalcType(_M_den[__k])) / __delta);
3264 __glibcxx_assert(__sum > 0);
3267 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
3270 __detail::__normalize(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), __sum);
3272 __detail::__normalize(_M_m.begin(), _M_m.end(), _M_m.begin(), __sum);
3275 _M_cp[_M_cp.size() - 1] = _CalcType(1);
3278 template<
typename _RealType>
3280 piecewise_linear_distribution<_RealType>::param_type::
3281 _M_initialize2(
const _RealType* __ints,
const _CalcType* __dens)
3283 if (__ints[0] == _RealType(0)
3284 && __ints[1] == _RealType(1)
3285 && __dens[0] == __dens[1])
3289 _M_int.push_back(__ints[0]);
3290 _M_int.push_back(__ints[1]);
3293 _M_den.push_back(__dens[0]);
3294 _M_den.push_back(__dens[1]);
3298 template<
typename _RealType>
3299 template<
typename _InputIteratorB,
typename _InputIteratorW>
3300 piecewise_linear_distribution<_RealType>::param_type::
3301 param_type(_InputIteratorB __bbegin,
3302 _InputIteratorB __bend,
3303 _InputIteratorW __wbegin)
3304 : _M_int(), _M_den(), _M_cp(), _M_m()
3306 _RealType __ints[2];
3307 if (!__detail::__load_first2(__bbegin, __bend, __ints))
3310 if (__bbegin == __bend)
3312 _CalcType __dens[2];
3313 __dens[0] = *__wbegin;
3315 __dens[1] = *__wbegin;
3316 _M_initialize2(__ints, __dens);
3320#if __glibcxx_concepts
3321 if constexpr (sized_sentinel_for<_InputIteratorB, _InputIteratorB>
3322 || forward_iterator<_InputIteratorB>)
3323 _M_int.reserve(2 +
size_t(ranges::distance(__bbegin, __bend)));
3325#pragma GCC diagnostic push
3326#pragma GCC diagnostic ignored "-Wc++17-extensions"
3327 if constexpr (is_convertible<__iter_category_t<_InputIteratorB>,
3329 _M_int.reserve(2 +
size_t(
std::distance(__bbegin, __bend)));
3330#pragma GCC diagnostic pop
3333 _M_int.push_back(__ints[0]);
3334 _M_int.push_back(__ints[1]);
3335 for (; __bbegin != __bend; ++__bbegin)
3336 _M_int.push_back(*__bbegin);
3340 _M_den.reserve(_M_int.size());
3341 for (
size_t __i = 0; __i < _M_int.size(); (void)++__i, ++__wbegin)
3342 _M_den.push_back(_CalcType(*__wbegin));
3347 template<
typename _RealType>
3348 template<
typename _Func>
3349 piecewise_linear_distribution<_RealType>::param_type::
3350 param_type(initializer_list<_RealType> __bl, _Func __fw)
3351 : _M_int(), _M_den(), _M_cp(), _M_m()
3353 if (__bl.size() < 2)
3356 if (__bl.size() == 2)
3358 const _RealType *__ints = __bl.begin();
3360 __den[0] = __fw(__ints[0]);
3361 __den[1] = __fw(__ints[1]);
3362 _M_initialize2(__ints, __den);
3367 _M_den.reserve(__bl.size());
3368 for (_RealType __b : __bl)
3369 _M_den.push_back(_CalcType(__fw(__b)));
3373 template<
typename _RealType>
3374 template<
typename _Func>
3375 piecewise_linear_distribution<_RealType>::param_type::
3376 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3377 : _M_int(), _M_den(), _M_cp(), _M_m()
3379 const size_t __n = __nw == 0 ? 1 : __nw;
3380 const _RealType __delta = (__xmax - __xmin) / __n;
3381 const auto __cfw = [&] (_RealType __v)
3383#ifdef _GLIBCXX_USE_OLD_PIECEWISE_DISTRIBUTIONS
3384 return __fw(__v + __delta);
3388 return _RealType(__fw(__v));
3394 _RealType __ints[2] = { __xmin, __xmin + __delta };
3395 _CalcType __dens[2];
3396 __dens[0] = __cfw(__ints[0]);
3397 __dens[1] = __cfw(__ints[1]);
3398 _M_initialize2(__ints, __dens);
3402 _M_int.reserve(__n + 1);
3403 _M_den.reserve(__n + 1);
3404 for (
size_t __k = 0; __k <= __nw; ++__k)
3406 _M_int.push_back(__xmin + __k * __delta);
3407 _M_den.push_back(__cfw(_M_int[__k]));
3413 template<
typename _RealType>
3414 template<
typename _AdaptedUniformRandomNumberGenerator>
3415 typename piecewise_linear_distribution<_RealType>::result_type
3416 piecewise_linear_distribution<_RealType>::
3417 __generate_one(_AdaptedUniformRandomNumberGenerator& __aurng,
3418 const param_type& __param)
3420 const _CalcType __p = __aurng();
3421 auto __pos = std::lower_bound(__param._M_cp.begin(),
3422 __param._M_cp.end(), __p);
3423 const size_t __i = __pos - __param._M_cp.begin();
3425 const _CalcType __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3427 const _CalcType __a = _CalcType(0.5) * __param._M_m[__i];
3428 const _CalcType __b = __param._M_den[__i];
3429 const _CalcType __cm = __p - __pref;
3431 _RealType __x = __param._M_int[__i];
3436 const _CalcType __d = __b * __b + 4.0 * __a * __cm;
3437 __x += _CalcType(0.5) * (
std::sqrt(__d) - __b) / __a;
3443 template<
typename _RealType>
3444 template<
typename _UniformRandomNumberGenerator>
3445 typename piecewise_linear_distribution<_RealType>::result_type
3446 piecewise_linear_distribution<_RealType>::
3447 operator()(_UniformRandomNumberGenerator& __urng,
3448 const param_type& __param)
3450 __detail::_Adaptor<_UniformRandomNumberGenerator, _CalcType>
3453 if (__param._M_cp.empty())
3456 return __generate_one(__aurng, __param);
3459 template<
typename _RealType>
3460 template<
typename _ForwardIterator,
3461 typename _UniformRandomNumberGenerator>
3463 piecewise_linear_distribution<_RealType>::
3464 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3465 _UniformRandomNumberGenerator& __urng,
3466 const param_type& __param)
3468 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3469 __detail::_Adaptor<_UniformRandomNumberGenerator, _CalcType>
3472 if (__param._M_cp.empty())
3477 *__f++ = __generate_one(__urng, __param);
3480 template<
typename _RealType,
typename _CharT,
typename _Traits>
3483 const piecewise_linear_distribution<_RealType>& __x)
3485 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
3487 const typename __ios_base::fmtflags __flags = __os.
flags();
3488 const _CharT __fill = __os.
fill();
3490 const _CharT __space = __os.
widen(
' ');
3491 __os.
flags(__ios_base::scientific | __ios_base::left);
3495 auto const& __int = __x._M_param._M_int;
3498 << __space << _RealType(0) << __space << _RealType(1)
3499 << __space << _RealType(1) << __space << _RealType(1);
3502 __os << __int.size() - 1;
3503 for (
auto __xv : __int)
3504 __os << __space << __xv;
3505 for (
auto __dv : __x._M_param._M_den)
3506 __os << __space << __dv;
3509 __os.
flags(__flags);
3515 template<
typename _RealType,
typename _CharT,
typename _Traits>
3518 piecewise_linear_distribution<_RealType>& __x)
3520 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3522 =
typename piecewise_linear_distribution<_RealType>::_StorageType;
3524 const typename __ios_base::fmtflags __flags = __is.
flags();
3525 __is.
flags(__ios_base::dec | __ios_base::skipws);
3530 vector<_RealType> __int_vec;
3531 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3533 vector<_StorageType> __den_vec;
3534 if (__detail::__extract_params(__is, __den_vec, __n + 1))
3536 __x.param({ __int_vec.begin(), __int_vec.end(),
3537 __den_vec.begin() });
3541 __is.
flags(__flags);
3546 template<
typename _IntType,
typename>
3549 _M_v.reserve(__il.size());
3550 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
3551 _M_v.push_back(__detail::__mod<result_type,
3552 __detail::_Shift<result_type, 32>::__value>(*__iter));
3555 template<
typename _InputIterator>
3556 seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
3558#pragma GCC diagnostic push
3559#pragma GCC diagnostic ignored "-Wc++17-extensions"
3560 if constexpr (__is_random_access_iter<_InputIterator>::value)
3562#pragma GCC diagnostic pop
3564 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
3565 _M_v.push_back(__detail::__mod<result_type,
3566 __detail::_Shift<result_type, 32>::__value>(*__iter));
3569 template<
typename _RandomAccessIterator>
3571 seed_seq::generate(_RandomAccessIterator __begin,
3572 _RandomAccessIterator __end)
3574 typedef typename iterator_traits<_RandomAccessIterator>::value_type
3577 if (__begin == __end)
3580 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
3582 const size_t __n = __end - __begin;
3583 const size_t __s = _M_v.size();
3584 const size_t __t = (__n >= 623) ? 11
3589 const size_t __p = (__n - __t) / 2;
3590 const size_t __q = __p + __t;
3591 const size_t __m =
std::max(
size_t(__s + 1), __n);
3593#ifndef __UINT32_TYPE__
3596 _Up(uint_least32_t v) : _M_v(v & 0xffffffffu) { }
3598 operator uint_least32_t()
const {
return _M_v; }
3600 uint_least32_t _M_v;
3602 using uint32_t = _Up;
3607 uint32_t __r1 = 1371501266u;
3608 uint32_t __r2 = __r1 + __s;
3609 __begin[__p] += __r1;
3610 __begin[__q] = (uint32_t)__begin[__q] + __r2;
3614 for (
size_t __k = 1; __k <= __s; ++__k)
3616 const size_t __kn = __k % __n;
3617 const size_t __kpn = (__k + __p) % __n;
3618 const size_t __kqn = (__k + __q) % __n;
3619 uint32_t __arg = (__begin[__kn]
3621 ^ __begin[(__k - 1) % __n]);
3622 uint32_t __r1 = 1664525u * (__arg ^ (__arg >> 27));
3623 uint32_t __r2 = __r1 + (uint32_t)__kn + _M_v[__k - 1];
3624 __begin[__kpn] = (uint32_t)__begin[__kpn] + __r1;
3625 __begin[__kqn] = (uint32_t)__begin[__kqn] + __r2;
3626 __begin[__kn] = __r2;
3629 for (
size_t __k = __s + 1; __k < __m; ++__k)
3631 const size_t __kn = __k % __n;
3632 const size_t __kpn = (__k + __p) % __n;
3633 const size_t __kqn = (__k + __q) % __n;
3634 uint32_t __arg = (__begin[__kn]
3636 ^ __begin[(__k - 1) % __n]);
3637 uint32_t __r1 = 1664525u * (__arg ^ (__arg >> 27));
3638 uint32_t __r2 = __r1 + (uint32_t)__kn;
3639 __begin[__kpn] = (uint32_t)__begin[__kpn] + __r1;
3640 __begin[__kqn] = (uint32_t)__begin[__kqn] + __r2;
3641 __begin[__kn] = __r2;
3644 for (
size_t __k = __m; __k < __m + __n; ++__k)
3646 const size_t __kn = __k % __n;
3647 const size_t __kpn = (__k + __p) % __n;
3648 const size_t __kqn = (__k + __q) % __n;
3649 uint32_t __arg = (__begin[__kn]
3651 + __begin[(__k - 1) % __n]);
3652 uint32_t __r3 = 1566083941u * (__arg ^ (__arg >> 27));
3653 uint32_t __r4 = __r3 - __kn;
3654 __begin[__kpn] ^= __r3;
3655 __begin[__kqn] ^= __r4;
3656 __begin[__kn] = __r4;
3663#ifndef _GLIBCXX_USE_OLD_GENERATE_CANONICAL
3665#pragma GCC diagnostic push
3666#pragma GCC diagnostic ignored "-Wc++14-extensions"
3667#pragma GCC diagnostic ignored "-Wc++17-extensions"
3699 template<
typename _RealT,
size_t __d,
typename _Urbg>
3701 __generate_canonical_pow2(_Urbg& __urng)
3703 using _UInt =
typename __detail::_Select_uint_least_t<__d>::type;
3709 using _Rng =
decltype(_Urbg::max());
3710 const _Rng __rng_range_less_1 = _Urbg::max() - _Urbg::min();
3712 const auto __log2_R = __builtin_popcountg(__rng_range_less_1);
3713 const auto __log2_uint_max =
sizeof(_UInt) * __CHAR_BIT__;
3715 const unsigned __k = (__d + __log2_R - 1) / __log2_R;
3716 const unsigned __log2_Rk_max = __k * __log2_R;
3717 const unsigned __log2_Rk =
3718 __log2_uint_max < __log2_Rk_max ? __log2_uint_max : __log2_Rk_max;
3720 _GLIBCXX14_CONSTEXPR
const _RealT __Rk
3721 = _RealT(_UInt(1) << (__log2_Rk - 1)) * _RealT(2.0);
3722#if defined(_GLIBCXX_GENERATE_CANONICAL_STRICT)
3723 const unsigned __log2_x = __log2_Rk - __d;
3725 const unsigned __log2_x = 0;
3727 _GLIBCXX14_CONSTEXPR
const _UInt __x = _UInt(1) << __log2_x;
3728 _GLIBCXX14_CONSTEXPR
const _RealT __rd = __Rk / _RealT(__x);
3733 _UInt __sum = _UInt(__urng() - _Urbg::min());
3734 for (
unsigned __i = __k - 1, __shift = 0; __i > 0; --__i)
3736 __shift += __log2_R;
3737 __sum |= _UInt(__urng() - _Urbg::min()) << __shift;
3739 const _RealT __ret = _RealT(__sum >> __log2_x) / _RealT(__rd);
3740 if (__ret < _RealT(1.0))
3746 template<
typename _UInt>
3747 struct __gen_canon_log_res
3749 unsigned __floor_log;
3752 constexpr __gen_canon_log_res
3753 update(_UInt __base)
const
3754 {
return {__floor_log + 1, __floor_pow *
__base}; }
3758 template <
typename _UInt1,
typename _UInt2,
3759 typename _UComm = __conditional_t<(
sizeof(_UInt2) >
sizeof(_UInt1)),
3761 constexpr __gen_canon_log_res<_UInt1>
3762 __gen_canon_log(_UInt1 __val, _UInt2 __base)
3764#if __cplusplus >= 201402L
3765 __gen_canon_log_res<_UInt1> __res{0, _UInt1(1)};
3766 if (_UComm(__base) > _UComm(__val))
3769 const _UInt1 __base1(__base);
3773 __res = __res.update(__base1);
3775 while (__val >= __base1);
3778 return (_UComm(__val) >= _UComm(__base))
3779 ? __gen_canon_log(__val / _UInt1(__base), _UInt1(__base))
3780 .update(_UInt1(__base))
3781 : __gen_canon_log_res<_UInt1>{0, _UInt1(1)};
3791 template<
typename _RealT,
size_t __d,
typename _Urbg>
3793 __generate_canonical_any(_Urbg& __urng)
3797#if (__cplusplus >= 201402L) || defined(__SIZEOF_INT128__)
3798# define _GLIBCXX_GEN_CANON_CONST constexpr
3800# define _GLIBCXX_GEN_CANON_CONST const
3803 using _UIntR =
typename make_unsigned<
decltype(_Urbg::max())>::type;
3806 constexpr _UIntR __R = _UIntR(_Urbg::max() - _Urbg::min()) + 1;
3807 constexpr unsigned __log2R
3808 =
sizeof(_UIntR) * __CHAR_BIT__ - __builtin_clzg(__R) - 1;
3813 constexpr unsigned __l = (__d + __log2R - 1) / __log2R;
3814 constexpr unsigned __bits = (__log2R + 1) * __l;
3815 using _UInt =
typename __detail::_Select_uint_least_t<__bits>::type;
3817 _GLIBCXX_GEN_CANON_CONST _UInt __rd = _UInt(1) << __d;
3818 _GLIBCXX_GEN_CANON_CONST
auto __logRrd = __gen_canon_log(__rd, __R);
3819 _GLIBCXX_GEN_CANON_CONST
unsigned __k
3820 = __logRrd.__floor_log + (__rd > __logRrd.__floor_pow);
3822 _GLIBCXX_GEN_CANON_CONST _UInt __Rk
3823 = (__k > __logRrd.__floor_log)
3824 ? _UInt(__logRrd.__floor_pow) * _UInt(__R)
3825 : _UInt(__logRrd.__floor_pow);
3826 _GLIBCXX_GEN_CANON_CONST _UInt __x = __Rk / __rd;
3831 _UInt __sum(__urng() - _Urbg::min());
3832 for (
int __i = __k - 1; __i > 0; --__i)
3835 __sum += _UInt(__urng() - _Urbg::min()) * __Ri;
3837 const _RealT __ret = _RealT(__sum / __x) / _RealT(__rd);
3838 if (__ret < _RealT(1.0))
3841#undef _GLIBCXX_GEN_CANON_CONST
3844#if !defined(_GLIBCXX_GENERATE_CANONICAL_STRICT)
3845 template <
typename _Tp>
3846 const bool __is_rand_dist_float_v = is_floating_point<_Tp>::value;
3848 template <
typename _Tp>
const bool __is_rand_dist_float_v =
false;
3849 template <>
const bool __is_rand_dist_float_v<float> =
true;
3850 template <>
const bool __is_rand_dist_float_v<double> =
true;
3851 template <>
const bool __is_rand_dist_float_v<long double> =
true;
3855 template <
typename _Rng>
3856 constexpr bool __is_power_of_2_less_1(_Rng __range)
3857 {
return ((__range + 1) & __range) == 0; };
3859_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
3875 template<
typename _RealT,
size_t __digits,
3880#ifdef __glibcxx_concepts
3883 static_assert(__is_rand_dist_float_v<_RealT>,
3884 "template argument must be a floating point type");
3885 static_assert(__digits != 0 && _Urbg::max() > _Urbg::min(),
3886 "random samples with 0 bits are not meaningful");
3888 "only base-2 float types are supported");
3889#if defined(__STDCPP_FLOAT16_T__)
3890 static_assert(! is_same_v<_RealT, _Float16>,
3891 "float16_t type is not supported, consider using bfloat16_t");
3895 const unsigned __d = __digits > __d_max ? __d_max : __digits;
3899 if constexpr (__is_power_of_2_less_1(_Urbg::max() - _Urbg::min()))
3900 return __generate_canonical_pow2<_RealT, __d>(__urng);
3902 return __generate_canonical_any<_RealT, __d>(__urng);
3904_GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
3906#pragma GCC diagnostic pop
3912 template<
typename _RealType,
size_t __bits,
3913 typename _UniformRandomNumberGenerator>
3915 generate_canonical(_UniformRandomNumberGenerator& __urng)
3918 "template argument must be a floating point type");
3923 const long double __r =
static_cast<long double>(__urng.max())
3924 -
static_cast<long double>(__urng.min()) + 1.0L;
3927 (__b + __log2r - 1UL) / __log2r);
3929 _RealType __sum = _RealType(0);
3930 _RealType __tmp = _RealType(1);
3931 for (
size_t __k = __m; __k != 0; --__k)
3933 __sum += _RealType(__urng() - __urng.min()) * __tmp;
3936 __ret = __sum / __tmp;
3937 if (__builtin_expect(__ret >= _RealType(1), 0))
3939# if _GLIBCXX_USE_C99_MATH_FUNCS
3940 __ret = std::nextafter(_RealType(1), _RealType(0));
3942 __ret = _RealType(1)
3951_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.
constexpr _Iterator __base(_Iterator __it)
A standard container for storing a fixed size sequence of elements.
Template class basic_istream.
static constexpr bool is_integer
static constexpr int max_digits10
static constexpr int digits
static constexpr bool is_signed
static constexpr int radix
static constexpr _Tp max() noexcept
static constexpr _Tp epsilon() noexcept
char_type widen(char __c) const
Widens characters.
char_type fill() const
Retrieves the empty character.
streamsize precision() const
Flags access.
fmtflags flags() const
Access to format flags.
Template class basic_ostream.
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
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
A discrete pseudorandom number generator with weak cryptographic properties.
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.
A discrete binomial 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.
Forward iterators support a superset of input iterator operations.
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.
Requirements for a uniform random bit generator.