@@ -402,7 +402,7 @@ bool _Nrand_for_tr1(
402
402
}
403
403
404
404
template <class _Gen, class = void>
405
- struct _Has_static_min_max : false_type {};
405
+ struct _Has_static_min_max : false_type {}; // TRANSITION, VSO-2417491: Should be a variable template
406
406
407
407
// This checks a requirement of N4981 [rand.req.urng] `concept uniform_random_bit_generator` but doesn't attempt
408
408
// to implement the whole concept - we just need to distinguish Standard machinery from tr1 machinery.
@@ -461,8 +461,6 @@ _NODISCARD _Real _Nrand_impl(_Gen& _Gx) { // build a floating-point value from r
461
461
}
462
462
}
463
463
464
- #define _NRAND(eng, resty) (_Nrand_impl<resty>(eng))
465
-
466
464
_INLINE_VAR constexpr int _MP_len = 5;
467
465
using _MP_arr = uint64_t[_MP_len];
468
466
@@ -2546,7 +2544,7 @@ public:
2546
2544
private:
2547
2545
template <class _Engine>
2548
2546
result_type _Eval(_Engine& _Eng, const param_type& _Par0) const {
2549
- return _NRAND (_Eng, double ) < _Par0._Px;
2547
+ return _Nrand_impl<double> (_Eng) < _Par0._Px;
2550
2548
}
2551
2549
2552
2550
param_type _Par;
@@ -2713,7 +2711,7 @@ private:
2713
2711
2714
2712
_Ty1 _Val;
2715
2713
do {
2716
- _Val = _CSTD log(_NRAND (_Eng, _Ty1 )) / _Par0._Log_1_p;
2714
+ _Val = _CSTD log(_Nrand_impl<_Ty1> (_Eng)) / _Par0._Log_1_p;
2717
2715
} while (_Val >= _Ty1_max);
2718
2716
return static_cast<_Ty>(_Val);
2719
2717
}
@@ -2730,7 +2728,7 @@ public:
2730
2728
_NODISCARD _Ty operator()(_Engine& _Eng) const {
2731
2729
_Ty1 _Val = 1.0;
2732
2730
for (_Ty _Res = 0;; ++_Res) { // count repetitions
2733
- _Val *= _NRAND (_Eng, _Ty1 );
2731
+ _Val *= _Nrand_impl<_Ty1> (_Eng);
2734
2732
if (_Val <= _Gx0) {
2735
2733
return _Res;
2736
2734
}
@@ -2882,15 +2880,15 @@ private:
2882
2880
_Ty _Res;
2883
2881
_Ty1 _Yx;
2884
2882
for (;;) { // generate a tentative value
2885
- _Yx = static_cast<_Ty1>(_CSTD tan(_Pi_val * _NRAND (_Eng, _Ty1 )));
2883
+ _Yx = static_cast<_Ty1>(_CSTD tan(_Pi_val * _Nrand_impl<_Ty1> (_Eng)));
2886
2884
const _Ty1 _Mx{_Par0._Sqrt * _Yx + _Par0._Mean};
2887
2885
if (0.0 <= _Mx && _Mx < _Ty1_max) {
2888
2886
_Res = static_cast<_Ty>(_Mx);
2889
2887
break;
2890
2888
}
2891
2889
}
2892
2890
2893
- if (_NRAND (_Eng, _Ty1 )
2891
+ if (_Nrand_impl<_Ty1> (_Eng)
2894
2892
<= 0.9 * (1.0 + _Yx * _Yx) * _CSTD exp(_Res * _Par0._Logm - _XLgamma(_Res + 1.0) - _Par0._Gx1)) {
2895
2893
return _Res;
2896
2894
}
@@ -3050,15 +3048,15 @@ private:
3050
3048
if (_Par0._Tx < 25) { // generate directly
3051
3049
_Res = 0;
3052
3050
for (_Ty _Ix = 0; _Ix < _Par0._Tx; ++_Ix) {
3053
- if (_NRAND (_Eng, _Ty1 ) < _Par0._Px) {
3051
+ if (_Nrand_impl<_Ty1> (_Eng) < _Par0._Px) {
3054
3052
++_Res;
3055
3053
}
3056
3054
}
3057
3055
3058
3056
return _Res;
3059
3057
} else if (_Par0._Mean < 1.0) {
3060
3058
// Events are rare, use waiting time method (Luc Devroye, Non-Uniform Random Variate Generation, p. 525).
3061
- const _Ty1 _Rand = _NRAND (_Eng, _Ty1 );
3059
+ const _Ty1 _Rand = _Nrand_impl<_Ty1> (_Eng);
3062
3060
3063
3061
// The exit condition is log(1 - _Rand)/t < log(1-p), which is equivalent to _Rand > 1 - (1-p)^t. If
3064
3062
// we have a cheap upper bound for 1-(1-p)^t, we can exit early without having to call log. We use two
@@ -3073,7 +3071,7 @@ private:
3073
3071
_Ty _Denom = _Par0._Tx;
3074
3072
_Ty1 _Sum = _CSTD log(_Ty1{1.0} - _Rand) / _Denom;
3075
3073
while (_Sum >= _Par0._Logp1 && --_Denom != 0) {
3076
- _Sum += _CSTD log(_Ty1{1.0} - _NRAND (_Eng, _Ty1 )) / _Denom;
3074
+ _Sum += _CSTD log(_Ty1{1.0} - _Nrand_impl<_Ty1> (_Eng)) / _Denom;
3077
3075
}
3078
3076
_Res = static_cast<_Ty>(_Par0._Tx - _Denom);
3079
3077
}
@@ -3084,14 +3082,14 @@ private:
3084
3082
for (;;) { // generate and reject
3085
3083
_Ty1 _Yx;
3086
3084
for (;;) { // generate a tentative value
3087
- _Yx = static_cast<_Ty1>(_CSTD tan(_Pi_val * _NRAND (_Eng, _Ty1 )));
3085
+ _Yx = static_cast<_Ty1>(_CSTD tan(_Pi_val * _Nrand_impl<_Ty1> (_Eng)));
3088
3086
const _Ty1 _Mx{_Par0._Sqrt * _Yx + _Par0._Mean};
3089
3087
if (0.0 <= _Mx && _Mx < _Ty1_Tx) {
3090
3088
_Res = static_cast<_Ty>(_Mx);
3091
3089
break;
3092
3090
}
3093
3091
}
3094
- if (_NRAND (_Eng, _Ty1 )
3092
+ if (_Nrand_impl<_Ty1> (_Eng)
3095
3093
<= 1.2 * _Par0._Sqrt * (1.0 + _Yx * _Yx)
3096
3094
* _CSTD exp(_Par0._Gx1 - _XLgamma(_Res + 1.0) - _XLgamma(_Par0._Tx - _Res + 1.0)
3097
3095
+ _Res * _Par0._Logp + (_Par0._Tx - _Res) * _Par0._Logp1)) {
@@ -3226,7 +3224,7 @@ public:
3226
3224
private:
3227
3225
template <class _Engine>
3228
3226
result_type _Eval(_Engine& _Eng, const param_type& _Par0) const {
3229
- return _NRAND (_Eng, _Ty ) * (_Par0._Max - _Par0._Min) + _Par0._Min;
3227
+ return _Nrand_impl<_Ty> (_Eng) * (_Par0._Max - _Par0._Min) + _Par0._Min;
3230
3228
}
3231
3229
3232
3230
param_type _Par;
@@ -3439,7 +3437,7 @@ public:
3439
3437
private:
3440
3438
template <class _Engine>
3441
3439
result_type _Eval(_Engine& _Eng, const param_type& _Par0) const {
3442
- return -_CSTD log(_Ty{1} - _NRAND (_Eng, _Ty )) / _Par0._Lambda;
3440
+ return -_CSTD log(_Ty{1} - _Nrand_impl<_Ty> (_Eng)) / _Par0._Lambda;
3443
3441
}
3444
3442
3445
3443
param_type _Par;
@@ -3600,8 +3598,8 @@ private:
3600
3598
_Ty _Vx2;
3601
3599
_Ty _Sx;
3602
3600
for (;;) { // reject bad values to avoid generating NaN/Inf on the next calculations
3603
- _Vx1 = 2 * _NRAND (_Eng, _Ty ) - 1;
3604
- _Vx2 = 2 * _NRAND (_Eng, _Ty ) - 1;
3601
+ _Vx1 = 2 * _Nrand_impl<_Ty> (_Eng) - 1;
3602
+ _Vx2 = 2 * _Nrand_impl<_Ty> (_Eng) - 1;
3605
3603
_Sx = _Vx1 * _Vx1 + _Vx2 * _Vx2;
3606
3604
if (_Sx < _Ty{1} && _Vx1 != _Ty{0} && _Vx2 != _Ty{0}) {
3607
3605
// good values!
@@ -3779,9 +3777,9 @@ private:
3779
3777
if (_Par0._Alpha < 1) { // small values of alpha
3780
3778
// from Knuth
3781
3779
for (;;) { // generate and reject
3782
- _Ux = _NRAND (_Eng, _Ty );
3780
+ _Ux = _Nrand_impl<_Ty> (_Eng);
3783
3781
do {
3784
- _Vx = _NRAND (_Eng, _Ty );
3782
+ _Vx = _Nrand_impl<_Ty> (_Eng);
3785
3783
} while (_Vx == 0);
3786
3784
3787
3785
if (_Ux < _Par0._Px) { // small _Ux
@@ -3792,7 +3790,7 @@ private:
3792
3790
_Qx = _CSTD pow(_Xx, _Par0._Alpha - 1);
3793
3791
}
3794
3792
3795
- if (_NRAND (_Eng, _Ty ) < _Qx) {
3793
+ if (_Nrand_impl<_Ty> (_Eng) < _Qx) {
3796
3794
return _Par0._Beta * _Xx;
3797
3795
}
3798
3796
}
@@ -3804,10 +3802,10 @@ private:
3804
3802
3805
3803
if (_Par0._Alpha < 20.0 && (_Count = static_cast<int>(_Par0._Alpha)) == _Par0._Alpha) {
3806
3804
// _Alpha is small integer, compute directly
3807
- _Yx = _NRAND (_Eng, _Ty );
3805
+ _Yx = _Nrand_impl<_Ty> (_Eng);
3808
3806
while (--_Count) { // adjust result
3809
3807
do {
3810
- _Ux = _NRAND (_Eng, _Ty );
3808
+ _Ux = _Nrand_impl<_Ty> (_Eng);
3811
3809
} while (_Ux == 0);
3812
3810
3813
3811
_Yx *= _Ux;
@@ -3817,12 +3815,12 @@ private:
3817
3815
3818
3816
// no shortcuts
3819
3817
for (;;) { // generate and reject
3820
- _Yx = static_cast<_Ty>(_CSTD tan(_Pi_val * _NRAND (_Eng, _Ty )));
3818
+ _Yx = static_cast<_Ty>(_CSTD tan(_Pi_val * _Nrand_impl<_Ty> (_Eng)));
3821
3819
_Xx = _Par0._Sqrt * _Yx + _Par0._Alpha - 1;
3822
3820
if (0 < _Xx
3823
- && _NRAND (_Eng, _Ty ) <= (1 + _Yx * _Yx)
3824
- * _CSTD exp((_Par0._Alpha - 1) * _CSTD log(_Xx / (_Par0._Alpha - 1))
3825
- - _Par0._Sqrt * _Yx)) {
3821
+ && _Nrand_impl<_Ty> (_Eng) <= (1 + _Yx * _Yx)
3822
+ * _CSTD exp((_Par0._Alpha - 1) * _CSTD log(_Xx / (_Par0._Alpha - 1))
3823
+ - _Par0._Sqrt * _Yx)) {
3826
3824
return _Par0._Beta * _Xx;
3827
3825
}
3828
3826
}
@@ -3959,7 +3957,7 @@ public:
3959
3957
private:
3960
3958
template <class _Engine>
3961
3959
result_type _Eval(_Engine& _Eng, const param_type& _Par0) const { // generate pseudo-random value
3962
- _Ty _Px = (_Ty{1} - _NRAND (_Eng, _Ty ));
3960
+ _Ty _Px = (_Ty{1} - _Nrand_impl<_Ty> (_Eng));
3963
3961
return _Par0._Bx * _CSTD pow(-_CSTD log(_Px), _Ty{1} / _Par0._Ax);
3964
3962
}
3965
3963
@@ -4093,7 +4091,7 @@ public:
4093
4091
private:
4094
4092
template <class _Engine>
4095
4093
result_type _Eval(_Engine& _Eng, const param_type& _Par0) const { // generate pseudo-random value
4096
- _Ty _Px = _NRAND (_Eng, _Ty );
4094
+ _Ty _Px = _Nrand_impl<_Ty> (_Eng);
4097
4095
return _Par0._Ax - _Par0._Bx * _CSTD log(-_CSTD log(_Px));
4098
4096
}
4099
4097
@@ -4481,7 +4479,7 @@ public:
4481
4479
private:
4482
4480
template <class _Engine>
4483
4481
result_type _Eval(_Engine& _Eng, const param_type& _Par0) const { // generate pseudo-random value
4484
- _Ty Px = _NRAND (_Eng, _Ty );
4482
+ _Ty Px = _Nrand_impl<_Ty> (_Eng);
4485
4483
return static_cast<_Ty>(_Par0._Ax + _Par0._Bx * _CSTD tan(_Pi_val * (Px - static_cast<_Ty>(0.5))));
4486
4484
}
4487
4485
@@ -4504,8 +4502,8 @@ public:
4504
4502
_Ty _Px1;
4505
4503
_Ty _Px2;
4506
4504
for (;;) { // reject large values
4507
- _Px1 = _NRAND (_Eng, _Ty );
4508
- _Px2 = _NRAND (_Eng, _Ty );
4505
+ _Px1 = _Nrand_impl<_Ty> (_Eng);
4506
+ _Px2 = _Nrand_impl<_Ty> (_Eng);
4509
4507
_Px1 = _CSTD pow(_Px1, _Ty{1} / _Ax);
4510
4508
_Px2 = _CSTD pow(_Px2, _Ty{1} / _Bx);
4511
4509
_Wx = _Px1 + _Px2;
@@ -5153,7 +5151,7 @@ public:
5153
5151
private:
5154
5152
template <class _Engine>
5155
5153
result_type _Eval(_Engine& _Eng, const param_type& _Par0) const {
5156
- double _Px = _NRAND (_Eng, double );
5154
+ double _Px = _Nrand_impl<double> (_Eng);
5157
5155
const auto _First = _Par0._Pcdf.begin();
5158
5156
const auto _Position = _STD lower_bound(_First, _Prev_iter(_Par0._Pcdf.end()), _Px);
5159
5157
return static_cast<result_type>(_Position - _First);
@@ -5706,7 +5704,6 @@ _STL_RESTORE_DEPRECATED_WARNING
5706
5704
#endif // _HAS_TR1_NAMESPACE
5707
5705
_STD_END
5708
5706
5709
- #undef _NRAND
5710
5707
#undef _DISTRIBUTION_CONST
5711
5708
5712
5709
// TRANSITION, GH-183
0 commit comments