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, (void) ++__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>
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::
2950 if (_M_int.size() < 2
2951 || (_M_int.size() == 2
2952 && _M_int[0] == _RealType(0)
2953 && _M_int[1] == _RealType(1)))
2962 __glibcxx_assert(__sum > 0);
2964 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
2967 _M_cp.reserve(_M_den.size());
2972 _M_cp[_M_cp.size() - 1] = 1.0;
2974 for (
size_t __k = 0; __k < _M_den.size(); ++__k)
2975 _M_den[__k] /= _M_int[__k + 1] - _M_int[__k];
2978 template<
typename _RealType>
2979 template<
typename _InputIteratorB,
typename _InputIteratorW>
2980 piecewise_constant_distribution<_RealType>::param_type::
2981 param_type(_InputIteratorB __bbegin,
2982 _InputIteratorB __bend,
2983 _InputIteratorW __wbegin)
2984 : _M_int(), _M_den(), _M_cp()
2986 if (__bbegin != __bend)
2990 _M_int.push_back(*__bbegin);
2992 if (__bbegin == __bend)
2995 _M_den.push_back(*__wbegin);
3003 template<
typename _RealType>
3004 template<
typename _Func>
3005 piecewise_constant_distribution<_RealType>::param_type::
3006 param_type(initializer_list<_RealType> __bl, _Func __fw)
3007 : _M_int(), _M_den(), _M_cp()
3009 _M_int.reserve(__bl.size());
3010 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3011 _M_int.push_back(*__biter);
3013 _M_den.reserve(_M_int.size() - 1);
3014 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3015 _M_den.push_back(__fw(0.5 * (_M_int[__k + 1] + _M_int[__k])));
3020 template<
typename _RealType>
3021 template<
typename _Func>
3022 piecewise_constant_distribution<_RealType>::param_type::
3023 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3024 : _M_int(), _M_den(), _M_cp()
3026 const size_t __n = __nw == 0 ? 1 : __nw;
3027 const _RealType __delta = (__xmax - __xmin) / __n;
3029 _M_int.reserve(__n + 1);
3030 for (
size_t __k = 0; __k <= __nw; ++__k)
3031 _M_int.push_back(__xmin + __k * __delta);
3033 _M_den.reserve(__n);
3034 for (
size_t __k = 0; __k < __nw; ++__k)
3035 _M_den.push_back(__fw(_M_int[__k] + 0.5 * __delta));
3040 template<
typename _RealType>
3041 template<
typename _UniformRandomNumberGenerator>
3042 typename piecewise_constant_distribution<_RealType>::result_type
3043 piecewise_constant_distribution<_RealType>::
3044 operator()(_UniformRandomNumberGenerator& __urng,
3045 const param_type& __param)
3047 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3050 const double __p = __aurng();
3051 if (__param._M_cp.empty())
3054 auto __pos = std::lower_bound(__param._M_cp.begin(),
3055 __param._M_cp.end(), __p);
3056 const size_t __i = __pos - __param._M_cp.begin();
3058 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3060 return __param._M_int[__i] + (__p - __pref) / __param._M_den[__i];
3063 template<
typename _RealType>
3064 template<
typename _ForwardIterator,
3065 typename _UniformRandomNumberGenerator>
3067 piecewise_constant_distribution<_RealType>::
3068 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3069 _UniformRandomNumberGenerator& __urng,
3070 const param_type& __param)
3072 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3073 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3076 if (__param._M_cp.empty())
3085 const double __p = __aurng();
3087 auto __pos = std::lower_bound(__param._M_cp.begin(),
3088 __param._M_cp.end(), __p);
3089 const size_t __i = __pos - __param._M_cp.begin();
3091 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3093 *__f++ = (__param._M_int[__i]
3094 + (__p - __pref) / __param._M_den[__i]);
3098 template<
typename _RealType,
typename _CharT,
typename _Traits>
3101 const piecewise_constant_distribution<_RealType>& __x)
3103 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
3105 const typename __ios_base::fmtflags __flags = __os.
flags();
3106 const _CharT __fill = __os.
fill();
3108 const _CharT __space = __os.
widen(
' ');
3109 __os.
flags(__ios_base::scientific | __ios_base::left);
3114 __os << __int.
size() - 1;
3116 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3117 __os << __space << *__xit;
3120 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3121 __os << __space << *__dit;
3123 __os.
flags(__flags);
3129 template<
typename _RealType,
typename _CharT,
typename _Traits>
3132 piecewise_constant_distribution<_RealType>& __x)
3134 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3136 const typename __ios_base::fmtflags __flags = __is.
flags();
3137 __is.
flags(__ios_base::dec | __ios_base::skipws);
3143 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3146 if (__detail::__extract_params(__is, __den_vec, __n))
3148 __x.param({ __int_vec.
begin(), __int_vec.
end(),
3149 __den_vec.
begin() });
3154 __is.
flags(__flags);
3159 template<
typename _RealType>
3161 piecewise_linear_distribution<_RealType>::param_type::
3164 if (_M_int.size() < 2
3165 || (_M_int.size() == 2
3166 && _M_int[0] == _RealType(0)
3167 && _M_int[1] == _RealType(1)
3168 && _M_den[0] == _M_den[1]))
3176 _M_cp.reserve(_M_int.size() - 1);
3177 _M_m.reserve(_M_int.size() - 1);
3178 for (
size_t __k = 0; __k < _M_int.size() - 1; ++__k)
3180 const _RealType __delta = _M_int[__k + 1] - _M_int[__k];
3181 __sum += 0.5 * (_M_den[__k + 1] + _M_den[__k]) * __delta;
3182 _M_cp.push_back(__sum);
3183 _M_m.push_back((_M_den[__k + 1] - _M_den[__k]) / __delta);
3185 __glibcxx_assert(__sum > 0);
3188 __detail::__normalize(_M_den.begin(), _M_den.end(), _M_den.begin(),
3191 __detail::__normalize(_M_cp.begin(), _M_cp.end(), _M_cp.begin(), __sum);
3193 __detail::__normalize(_M_m.begin(), _M_m.end(), _M_m.begin(), __sum);
3196 _M_cp[_M_cp.size() - 1] = 1.0;
3199 template<
typename _RealType>
3200 template<
typename _InputIteratorB,
typename _InputIteratorW>
3201 piecewise_linear_distribution<_RealType>::param_type::
3202 param_type(_InputIteratorB __bbegin,
3203 _InputIteratorB __bend,
3204 _InputIteratorW __wbegin)
3205 : _M_int(), _M_den(), _M_cp(), _M_m()
3207 for (; __bbegin != __bend; ++__bbegin, (void) ++__wbegin)
3209 _M_int.push_back(*__bbegin);
3210 _M_den.push_back(*__wbegin);
3216 template<
typename _RealType>
3217 template<
typename _Func>
3218 piecewise_linear_distribution<_RealType>::param_type::
3219 param_type(initializer_list<_RealType> __bl, _Func __fw)
3220 : _M_int(), _M_den(), _M_cp(), _M_m()
3222 _M_int.reserve(__bl.size());
3223 _M_den.reserve(__bl.size());
3224 for (
auto __biter = __bl.begin(); __biter != __bl.end(); ++__biter)
3226 _M_int.push_back(*__biter);
3227 _M_den.push_back(__fw(*__biter));
3233 template<
typename _RealType>
3234 template<
typename _Func>
3235 piecewise_linear_distribution<_RealType>::param_type::
3236 param_type(
size_t __nw, _RealType __xmin, _RealType __xmax, _Func __fw)
3237 : _M_int(), _M_den(), _M_cp(), _M_m()
3239 const size_t __n = __nw == 0 ? 1 : __nw;
3240 const _RealType __delta = (__xmax - __xmin) / __n;
3242 _M_int.reserve(__n + 1);
3243 _M_den.reserve(__n + 1);
3244 for (
size_t __k = 0; __k <= __nw; ++__k)
3246 _M_int.push_back(__xmin + __k * __delta);
3247 _M_den.push_back(__fw(_M_int[__k] + __delta));
3253 template<
typename _RealType>
3254 template<
typename _UniformRandomNumberGenerator>
3255 typename piecewise_linear_distribution<_RealType>::result_type
3256 piecewise_linear_distribution<_RealType>::
3257 operator()(_UniformRandomNumberGenerator& __urng,
3258 const param_type& __param)
3260 __detail::_Adaptor<_UniformRandomNumberGenerator, double>
3263 const double __p = __aurng();
3264 if (__param._M_cp.empty())
3267 auto __pos = std::lower_bound(__param._M_cp.begin(),
3268 __param._M_cp.end(), __p);
3269 const size_t __i = __pos - __param._M_cp.begin();
3271 const double __pref = __i > 0 ? __param._M_cp[__i - 1] : 0.0;
3273 const double __a = 0.5 * __param._M_m[__i];
3274 const double __b = __param._M_den[__i];
3275 const double __cm = __p - __pref;
3277 _RealType __x = __param._M_int[__i];
3282 const double __d = __b * __b + 4.0 * __a * __cm;
3283 __x += 0.5 * (
std::sqrt(__d) - __b) / __a;
3289 template<
typename _RealType>
3290 template<
typename _ForwardIterator,
3291 typename _UniformRandomNumberGenerator>
3293 piecewise_linear_distribution<_RealType>::
3294 __generate_impl(_ForwardIterator __f, _ForwardIterator __t,
3295 _UniformRandomNumberGenerator& __urng,
3296 const param_type& __param)
3298 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
3301 *__f++ = this->operator()(__urng, __param);
3304 template<
typename _RealType,
typename _CharT,
typename _Traits>
3307 const piecewise_linear_distribution<_RealType>& __x)
3309 using __ios_base =
typename basic_ostream<_CharT, _Traits>::ios_base;
3311 const typename __ios_base::fmtflags __flags = __os.
flags();
3312 const _CharT __fill = __os.
fill();
3314 const _CharT __space = __os.
widen(
' ');
3315 __os.
flags(__ios_base::scientific | __ios_base::left);
3320 __os << __int.
size() - 1;
3322 for (
auto __xit = __int.
begin(); __xit != __int.
end(); ++__xit)
3323 __os << __space << *__xit;
3326 for (
auto __dit = __den.
begin(); __dit != __den.
end(); ++__dit)
3327 __os << __space << *__dit;
3329 __os.
flags(__flags);
3335 template<
typename _RealType,
typename _CharT,
typename _Traits>
3338 piecewise_linear_distribution<_RealType>& __x)
3340 using __ios_base =
typename basic_istream<_CharT, _Traits>::ios_base;
3342 const typename __ios_base::fmtflags __flags = __is.
flags();
3343 __is.
flags(__ios_base::dec | __ios_base::skipws);
3348 vector<_RealType> __int_vec;
3349 if (__detail::__extract_params(__is, __int_vec, __n + 1))
3351 vector<double> __den_vec;
3352 if (__detail::__extract_params(__is, __den_vec, __n + 1))
3354 __x.param({ __int_vec.begin(), __int_vec.end(),
3355 __den_vec.begin() });
3359 __is.
flags(__flags);
3364 template<
typename _IntType,
typename>
3367 _M_v.reserve(__il.size());
3368 for (
auto __iter = __il.begin(); __iter != __il.end(); ++__iter)
3369 _M_v.push_back(__detail::__mod<result_type,
3370 __detail::_Shift<result_type, 32>::__value>(*__iter));
3373 template<
typename _InputIterator>
3374 seed_seq::seed_seq(_InputIterator __begin, _InputIterator __end)
3376#pragma GCC diagnostic push
3377#pragma GCC diagnostic ignored "-Wc++17-extensions"
3378 if constexpr (__is_random_access_iter<_InputIterator>::value)
3380#pragma GCC diagnostic pop
3382 for (_InputIterator __iter = __begin; __iter != __end; ++__iter)
3383 _M_v.push_back(__detail::__mod<result_type,
3384 __detail::_Shift<result_type, 32>::__value>(*__iter));
3387 template<
typename _RandomAccessIterator>
3389 seed_seq::generate(_RandomAccessIterator __begin,
3390 _RandomAccessIterator __end)
3392 typedef typename iterator_traits<_RandomAccessIterator>::value_type
3395 if (__begin == __end)
3398 std::fill(__begin, __end, _Type(0x8b8b8b8bu));
3400 const size_t __n = __end - __begin;
3401 const size_t __s = _M_v.size();
3402 const size_t __t = (__n >= 623) ? 11
3407 const size_t __p = (__n - __t) / 2;
3408 const size_t __q = __p + __t;
3409 const size_t __m =
std::max(
size_t(__s + 1), __n);
3411#ifndef __UINT32_TYPE__
3414 _Up(uint_least32_t v) : _M_v(v & 0xffffffffu) { }
3416 operator uint_least32_t()
const {
return _M_v; }
3418 uint_least32_t _M_v;
3420 using uint32_t = _Up;
3425 uint32_t __r1 = 1371501266u;
3426 uint32_t __r2 = __r1 + __s;
3427 __begin[__p] += __r1;
3428 __begin[__q] = (uint32_t)__begin[__q] + __r2;
3432 for (
size_t __k = 1; __k <= __s; ++__k)
3434 const size_t __kn = __k % __n;
3435 const size_t __kpn = (__k + __p) % __n;
3436 const size_t __kqn = (__k + __q) % __n;
3437 uint32_t __arg = (__begin[__kn]
3439 ^ __begin[(__k - 1) % __n]);
3440 uint32_t __r1 = 1664525u * (__arg ^ (__arg >> 27));
3441 uint32_t __r2 = __r1 + (uint32_t)__kn + _M_v[__k - 1];
3442 __begin[__kpn] = (uint32_t)__begin[__kpn] + __r1;
3443 __begin[__kqn] = (uint32_t)__begin[__kqn] + __r2;
3444 __begin[__kn] = __r2;
3447 for (
size_t __k = __s + 1; __k < __m; ++__k)
3449 const size_t __kn = __k % __n;
3450 const size_t __kpn = (__k + __p) % __n;
3451 const size_t __kqn = (__k + __q) % __n;
3452 uint32_t __arg = (__begin[__kn]
3454 ^ __begin[(__k - 1) % __n]);
3455 uint32_t __r1 = 1664525u * (__arg ^ (__arg >> 27));
3456 uint32_t __r2 = __r1 + (uint32_t)__kn;
3457 __begin[__kpn] = (uint32_t)__begin[__kpn] + __r1;
3458 __begin[__kqn] = (uint32_t)__begin[__kqn] + __r2;
3459 __begin[__kn] = __r2;
3462 for (
size_t __k = __m; __k < __m + __n; ++__k)
3464 const size_t __kn = __k % __n;
3465 const size_t __kpn = (__k + __p) % __n;
3466 const size_t __kqn = (__k + __q) % __n;
3467 uint32_t __arg = (__begin[__kn]
3469 + __begin[(__k - 1) % __n]);
3470 uint32_t __r3 = 1566083941u * (__arg ^ (__arg >> 27));
3471 uint32_t __r4 = __r3 - __kn;
3472 __begin[__kpn] ^= __r3;
3473 __begin[__kqn] ^= __r4;
3474 __begin[__kn] = __r4;
3481#ifndef _GLIBCXX_USE_OLD_GENERATE_CANONICAL
3483#pragma GCC diagnostic push
3484#pragma GCC diagnostic ignored "-Wc++14-extensions"
3485#pragma GCC diagnostic ignored "-Wc++17-extensions"
3517 template<
typename _RealT,
size_t __d,
typename _Urbg>
3519 __generate_canonical_pow2(_Urbg& __urng)
3521 using _UInt =
typename __detail::_Select_uint_least_t<__d>::type;
3527 using _Rng =
decltype(_Urbg::max());
3528 const _Rng __rng_range_less_1 = _Urbg::max() - _Urbg::min();
3530 const auto __log2_R = __builtin_popcountg(__rng_range_less_1);
3531 const auto __log2_uint_max =
sizeof(_UInt) * __CHAR_BIT__;
3533 const unsigned __k = (__d + __log2_R - 1) / __log2_R;
3534 const unsigned __log2_Rk_max = __k * __log2_R;
3535 const unsigned __log2_Rk =
3536 __log2_uint_max < __log2_Rk_max ? __log2_uint_max : __log2_Rk_max;
3538 _GLIBCXX14_CONSTEXPR
const _RealT __Rk
3539 = _RealT(_UInt(1) << (__log2_Rk - 1)) * _RealT(2.0);
3540#if defined(_GLIBCXX_GENERATE_CANONICAL_STRICT)
3541 const unsigned __log2_x = __log2_Rk - __d;
3543 const unsigned __log2_x = 0;
3545 _GLIBCXX14_CONSTEXPR
const _UInt __x = _UInt(1) << __log2_x;
3546 _GLIBCXX14_CONSTEXPR
const _RealT __rd = __Rk / _RealT(__x);
3551 _UInt __sum = _UInt(__urng() - _Urbg::min());
3552 for (
unsigned __i = __k - 1, __shift = 0; __i > 0; --__i)
3554 __shift += __log2_R;
3555 __sum |= _UInt(__urng() - _Urbg::min()) << __shift;
3557 const _RealT __ret = _RealT(__sum >> __log2_x) / _RealT(__rd);
3558 if (__ret < _RealT(1.0))
3564 template<
typename _UInt>
3565 struct __gen_canon_log_res
3567 unsigned __floor_log;
3570 constexpr __gen_canon_log_res
3571 update(_UInt __base)
const
3572 {
return {__floor_log + 1, __floor_pow *
__base}; }
3576 template <
typename _UInt1,
typename _UInt2,
3577 typename _UComm = __conditional_t<(
sizeof(_UInt2) >
sizeof(_UInt1)),
3579 constexpr __gen_canon_log_res<_UInt1>
3580 __gen_canon_log(_UInt1 __val, _UInt2 __base)
3582#if __cplusplus >= 201402L
3583 __gen_canon_log_res<_UInt1> __res{0, _UInt1(1)};
3584 if (_UComm(__base) > _UComm(__val))
3587 const _UInt1 __base1(__base);
3591 __res = __res.update(__base1);
3593 while (__val >= __base1);
3596 return (_UComm(__val) >= _UComm(__base))
3597 ? __gen_canon_log(__val / _UInt1(__base), _UInt1(__base))
3598 .update(_UInt1(__base))
3599 : __gen_canon_log_res<_UInt1>{0, _UInt1(1)};
3609 template<
typename _RealT,
size_t __d,
typename _Urbg>
3611 __generate_canonical_any(_Urbg& __urng)
3615#if (__cplusplus >= 201402L) || defined(__SIZEOF_INT128__)
3616# define _GLIBCXX_GEN_CANON_CONST constexpr
3618# define _GLIBCXX_GEN_CANON_CONST const
3621 using _UIntR =
typename make_unsigned<
decltype(_Urbg::max())>::type;
3624 constexpr _UIntR __R = _UIntR(_Urbg::max() - _Urbg::min()) + 1;
3625 constexpr unsigned __log2R
3626 =
sizeof(_UIntR) * __CHAR_BIT__ - __builtin_clzg(__R) - 1;
3631 constexpr unsigned __l = (__d + __log2R - 1) / __log2R;
3632 constexpr unsigned __bits = (__log2R + 1) * __l;
3633 using _UInt =
typename __detail::_Select_uint_least_t<__bits>::type;
3635 _GLIBCXX_GEN_CANON_CONST _UInt __rd = _UInt(1) << __d;
3636 _GLIBCXX_GEN_CANON_CONST
auto __logRrd = __gen_canon_log(__rd, __R);
3637 _GLIBCXX_GEN_CANON_CONST
unsigned __k
3638 = __logRrd.__floor_log + (__rd > __logRrd.__floor_pow);
3640 _GLIBCXX_GEN_CANON_CONST _UInt __Rk
3641 = (__k > __logRrd.__floor_log)
3642 ? _UInt(__logRrd.__floor_pow) * _UInt(__R)
3643 : _UInt(__logRrd.__floor_pow);
3644 _GLIBCXX_GEN_CANON_CONST _UInt __x = __Rk / __rd;
3649 _UInt __sum(__urng() - _Urbg::min());
3650 for (
int __i = __k - 1; __i > 0; --__i)
3653 __sum += _UInt(__urng() - _Urbg::min()) * __Ri;
3655 const _RealT __ret = _RealT(__sum / __x) / _RealT(__rd);
3656 if (__ret < _RealT(1.0))
3659#undef _GLIBCXX_GEN_CANON_CONST
3662#if !defined(_GLIBCXX_GENERATE_CANONICAL_STRICT)
3663 template <
typename _Tp>
3664 const bool __is_rand_dist_float_v = is_floating_point<_Tp>::value;
3666 template <
typename _Tp>
const bool __is_rand_dist_float_v =
false;
3667 template <>
const bool __is_rand_dist_float_v<float> =
true;
3668 template <>
const bool __is_rand_dist_float_v<double> =
true;
3669 template <>
const bool __is_rand_dist_float_v<long double> =
true;
3673 template <
typename _Rng>
3674 constexpr bool __is_power_of_2_less_1(_Rng __range)
3675 {
return ((__range + 1) & __range) == 0; };
3677_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
3693 template<
typename _RealT,
size_t __digits,
3698#ifdef __glibcxx_concepts
3701 static_assert(__is_rand_dist_float_v<_RealT>,
3702 "template argument must be a floating point type");
3703 static_assert(__digits != 0 && _Urbg::max() > _Urbg::min(),
3704 "random samples with 0 bits are not meaningful");
3706 "only base-2 float types are supported");
3707#if defined(__STDCPP_FLOAT16_T__)
3708 static_assert(! is_same_v<_RealT, _Float16>,
3709 "float16_t type is not supported, consider using bfloat16_t");
3713 const unsigned __d = __digits > __d_max ? __d_max : __digits;
3717 if constexpr (__is_power_of_2_less_1(_Urbg::max() - _Urbg::min()))
3718 return __generate_canonical_pow2<_RealT, __d>(__urng);
3720 return __generate_canonical_any<_RealT, __d>(__urng);
3722_GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
3724#pragma GCC diagnostic pop
3730 template<
typename _RealType,
size_t __bits,
3731 typename _UniformRandomNumberGenerator>
3733 generate_canonical(_UniformRandomNumberGenerator& __urng)
3736 "template argument must be a floating point type");
3741 const long double __r =
static_cast<long double>(__urng.max())
3742 -
static_cast<long double>(__urng.min()) + 1.0L;
3745 (__b + __log2r - 1UL) / __log2r);
3747 _RealType __sum = _RealType(0);
3748 _RealType __tmp = _RealType(1);
3749 for (
size_t __k = __m; __k != 0; --__k)
3751 __sum += _RealType(__urng() - __urng.min()) * __tmp;
3754 __ret = __sum / __tmp;
3755 if (__builtin_expect(__ret >= _RealType(1), 0))
3757# if _GLIBCXX_USE_C99_MATH_FUNCS
3758 __ret = std::nextafter(_RealType(1), _RealType(0));
3760 __ret = _RealType(1)
3769_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.
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 int radix
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
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.
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.