Skip to content

Commit 6f7eb15

Browse files
committed
Change the base to the most recent commit on master
1 parent b90b3e0 commit 6f7eb15

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

stl/inc/random

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,7 +2936,7 @@ private:
29362936
_Vx1 = 2 * _NRAND(_Eng, _Ty) - 1;
29372937
_Vx2 = 2 * _NRAND(_Eng, _Ty) - 1;
29382938
_Sx = _Vx1 * _Vx1 + _Vx2 * _Vx2;
2939-
if (_Sx < 1) {
2939+
if (_Sx < 1 && _Sx != 0) {
29402940
break;
29412941
}
29422942
}
@@ -3864,19 +3864,29 @@ public:
38643864
_Px1 = _CSTD pow(_Px1, _Ty{1} / _Ax);
38653865
_Px2 = _CSTD pow(_Px2, _Ty{1} / _Bx);
38663866
_Wx = _Px1 + _Px2;
3867-
if (_Wx <= _Ty{1}) {
3867+
if (_Wx <= _Ty{1} && _Wx != _Ty{0}) {
38683868
break;
38693869
}
38703870
}
38713871
return _Px1 / _Wx;
38723872
} else { // use gamma distributions instead
38733873
_Ty _Px1;
38743874
_Ty _Px2;
3875+
_Ty _PSum;
38753876
gamma_distribution<_Ty> _Dist1(_Ax, 1);
38763877
gamma_distribution<_Ty> _Dist2(_Bx, 1);
3877-
_Px1 = _Dist1(_Eng);
3878-
_Px2 = _Dist2(_Eng);
3879-
return _Px1 / (_Px1 + _Px2);
3878+
3879+
for (;;) { // reject pairs whose sum is zero
3880+
_Px1 = _Dist1(_Eng);
3881+
_Px2 = _Dist2(_Eng);
3882+
_PSum = _Px1 + _Px2;
3883+
3884+
if (_PSum != _Ty{0}) {
3885+
break;
3886+
}
3887+
}
3888+
3889+
return _Px1 / _PSum;
38803890
}
38813891
}
38823892

@@ -4001,12 +4011,18 @@ private:
40014011
_Ty _Px;
40024012
_Ty _Vx1;
40034013
_Ty _Vx2;
4014+
const _Ty _Vx3{1};
40044015
_Vx1 = static_cast<_Ty>(_Par0._Mx) * static_cast<_Ty>(0.5);
40054016
_Vx2 = static_cast<_Ty>(_Par0._Nx) * static_cast<_Ty>(0.5);
40064017
_Beta_distribution<_Ty> _Dist(_Vx1, _Vx2);
4007-
_Px = _Dist(_Eng);
4018+
for (;;) { // reject bad values
4019+
_Px = _Dist(_Eng);
4020+
if (_Px != _Vx3) {
4021+
break;
4022+
}
4023+
}
40084024

4009-
return (_Vx2 / _Vx1) * (_Px / (_Ty{1} - _Px));
4025+
return (_Vx2 / _Vx1) * (_Px / (_Vx3 - _Px));
40104026
}
40114027

40124028
param_type _Par;
@@ -4137,7 +4153,7 @@ private:
41374153
_Vx2 = _Dist(_Eng);
41384154
_Rs = _Vx1 * _Vx1 + _Vx2 * _Vx2;
41394155

4140-
if (_Rs < _Ty{1}) {
4156+
if (_Rs < _Ty{1} && _Rs != _Ty{0}) {
41414157
break;
41424158
}
41434159
}

0 commit comments

Comments
 (0)