Skip to content

Commit

Permalink
<random>: Optimize range adjustment in uniform_int (#4234)
Browse files Browse the repository at this point in the history
  • Loading branch information
horenmar authored Dec 7, 2023
1 parent 706b425 commit f89e70e
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions stl/inc/random
Original file line number Diff line number Diff line change
Expand Up @@ -2089,12 +2089,7 @@ private:
static _Uty _Adjust(_Uty _Uval) noexcept { // convert signed ranges to unsigned ranges and vice versa
if constexpr (is_signed_v<_Ty>) {
constexpr _Uty _Adjuster = (static_cast<_Uty>(-1) >> 1) + 1; // 2^(N-1)

if (_Uval < _Adjuster) {
return static_cast<_Uty>(_Uval + _Adjuster);
} else {
return static_cast<_Uty>(_Uval - _Adjuster);
}
return static_cast<_Uty>(_Uval ^ _Adjuster);
} else { // _Ty is already unsigned, do nothing
return _Uval;
}
Expand Down

0 comments on commit f89e70e

Please sign in to comment.