@@ -637,19 +637,20 @@ class uint128_t {
637
637
uint128_t operator <<(const T p) {
638
638
if (!p) {
639
639
return uint128_t (f, s);
640
- }
641
- if (p >= 64 && p <= 128 ) {
640
+ } else if (p >= 64 && p <= 128 ) {
642
641
return uint128_t ((this ->s << (p - 64 )), 0 );
642
+ } else if (p < 64 && p > 0 ) {
643
+ return uint128_t ((this ->f << p) + ((this ->s >> (64 - p))),
644
+ this ->s << p);
643
645
}
644
- return uint128_t ((this ->f << p) + ((this ->s >> (64 - p))),
645
- this ->s << p);
646
+ return uint128_t (0 );
646
647
}
647
648
648
649
template <typename T, typename = typename std::enable_if<
649
650
std::is_integral<T>::value, T>::type>
650
651
uint128_t &operator <<=(const T p) {
651
652
if (p) {
652
- if (p >= 64 ) {
653
+ if (p >= 64 && p <= 128 ) {
653
654
this ->f = (this ->s << (p - 64 ));
654
655
this ->s = 0 ;
655
656
} else {
@@ -665,12 +666,13 @@ class uint128_t {
665
666
uint128_t operator >>(const T p) {
666
667
if (!p) {
667
668
return uint128_t (this ->f , this ->s );
668
- }
669
- if (p >= 64 ) {
669
+ } else if (p >= 64 && p <= 128 ) {
670
670
return uint128_t (0 , (this ->f >> (p - 64 )));
671
+ } else if (p < 64 && p > 0 ) {
672
+ return uint128_t ((this ->f >> p),
673
+ (this ->s >> p) + (this ->f << (64 - p)));
671
674
}
672
- return uint128_t ((this ->f >> p),
673
- (this ->s >> p) + (this ->f << (64 - p)));
675
+ return uint128_t (0 );
674
676
}
675
677
676
678
template <typename T, typename = typename std::enable_if<
0 commit comments