@@ -18,18 +18,16 @@ namespace mstd {
1818#endif
1919 static constexpr bool add_overflow (const _Na& a, const _Nb& b, _N& out) {
2020 if constexpr (are_unsigned_v<_N, _Na, _Nb>) {
21- if (a > std::numeric_limits<_N>(). max () - b) {
21+ if (a > std::numeric_limits<_N>:: max () - b) {
2222 return true ;
2323 }
2424 }
2525 else {
26- const std::numeric_limits<_N>& limit = std::numeric_limits<_N>();
27-
28- if (b >= 0 && a > limit.max () - b) {
26+ if (b >= 0 && a > std::numeric_limits<_N>::max () - b) {
2927 return true ;
3028 }
3129
32- if (b <= 0 && a < limit. min () - b) {
30+ if (b <= 0 && a < std::numeric_limits<_N>:: min () - b) {
3331 return true ;
3432 }
3533 }
@@ -45,18 +43,16 @@ namespace mstd {
4543#endif
4644 static constexpr bool sub_overflow (const _Na& a, const _Nb& b, _N& out) {
4745 if constexpr (are_unsigned_v<_N, _Na, _Nb>) {
48- if (a < std::numeric_limits<_N>(). min () + b) {
46+ if (a < std::numeric_limits<_N>:: min () + b) {
4947 return true ;
5048 }
5149 }
5250 else {
53- const std::numeric_limits<_N>& limit = std::numeric_limits<_N>();
54-
55- if (b <= 0 && a > limit.max () + b) {
51+ if (b <= 0 && a > std::numeric_limits<_N>::max () + b) {
5652 return true ;
5753 }
5854
59- if (b >= 0 && a < limit. min () + b) {
55+ if (b >= 0 && a < std::numeric_limits<_N>:: min () + b) {
6056 return true ;
6157 }
6258 }
@@ -72,29 +68,25 @@ namespace mstd {
7268#endif
7369 static constexpr bool mul_overflow (const _Na& a, const _Nb& b, _N& out) {
7470 if constexpr (are_unsigned_v<_N, _Na, _Nb>) {
75- if (a != 0 && b != 0 && a > std::numeric_limits<_N>(). max () / b) {
71+ if (a != 0 && b != 0 && a > std::numeric_limits<_N>:: max () / b) {
7672 return true ;
7773 }
7874 }
7975 else {
80- const std::numeric_limits<_N>& limit = std::numeric_limits<_N>();
81- const _N& min = limit.min ();
82- const _N& max = limit.max ();
83-
8476 if (a != 0 && b != 0 ) {
85- if (a == -1 && b == min) {
77+ if (a == -1 && b == std::numeric_limits<_N>:: min () ) {
8678 return true ;
8779 }
8880
89- if (a == min && b == -1 ) {
81+ if (a == std::numeric_limits<_N>:: min () && b == -1 ) {
9082 return true ;
9183 }
9284
93- if (a > max / b) {
85+ if (a > std::numeric_limits<_N>:: max () / b) {
9486 return true ;
9587 }
9688
97- if (a < min / b) {
89+ if (a < std::numeric_limits<_N>:: min () / b) {
9890 return true ;
9991 }
10092 }
@@ -111,18 +103,14 @@ namespace mstd {
111103#endif
112104 static constexpr bool div_overflow (const _Na& a, const _Nb& b, _N& out) {
113105 if constexpr (are_unsigned_v<_N, _Na, _Nb>) {
114- out = b == 0 ? std::numeric_limits<_N>(). max () : a / b;
106+ out = b == 0 ? std::numeric_limits<_N>:: max () : a / b;
115107 }
116108 else {
117- const std::numeric_limits<_N>& limit = std::numeric_limits<_N>();
118- const _N& min = limit.min ();
119- const _N& max = limit.max ();
120-
121- if (a == min && b == -1 ) {
109+ if (a == std::numeric_limits<_N>::min () && b == -1 ) {
122110 return true ;
123111 }
124112
125- out = b == 0 ? (a < 0 ? min : max) : a / b;
113+ out = b == 0 ? (a < 0 ? std::numeric_limits<_N>:: min () : std::numeric_limits<_N>:: max () ) : a / b;
126114 }
127115 return false ;
128116 }
0 commit comments