[Groonga-commit] groonga/grnxx at d01b37d [master] Add arighmetic/logical_right_shift() to Int. (#88)

Zurück zum Archiv-Index

susumu.yata null+****@clear*****
Fri Oct 24 12:42:51 JST 2014


susumu.yata	2014-10-24 12:42:51 +0900 (Fri, 24 Oct 2014)

  New Revision: d01b37d12c470114c356c1ecc8ac4bd7d2095578
  https://github.com/groonga/grnxx/commit/d01b37d12c470114c356c1ecc8ac4bd7d2095578

  Message:
    Add arighmetic/logical_right_shift() to Int. (#88)

  Modified files:
    include/grnxx/new_types/int.hpp

  Modified: include/grnxx/new_types/int.hpp (+14 -3)
===================================================================
--- include/grnxx/new_types/int.hpp    2014-10-24 11:00:51 +0900 (9c0b126)
+++ include/grnxx/new_types/int.hpp    2014-10-24 12:42:51 +0900 (698c5be)
@@ -113,10 +113,9 @@ class Int {
             (static_cast<uint64_t>(rhs.value_) >= 64)) ?
            na() : Int(value_ << rhs.value_);
   }
+  // NOTE: This is an arithmetic shift.
   constexpr Int operator>>(Int rhs) const {
-    return (is_na() || rhs.is_na() ||
-            (static_cast<uint64_t>(rhs.value_) >= 64)) ?
-           na() : Int(value_ >> rhs.value_);
+    return arithmetic_right_shift(rhs);
   }
 
   Int &operator<<=(Int rhs) & {
@@ -129,6 +128,7 @@ class Int {
     }
     return *this;
   }
+  // NOTE: This is an arithmetic shift.
   Int &operator>>=(Int rhs) & {
     if (!is_na()) {
       if (rhs.is_na() || (static_cast<uint64_t>(rhs.value_) >= 64)) {
@@ -140,6 +140,17 @@ class Int {
     return *this;
   }
 
+  constexpr Int arighmetic_right_shift(Int rhs) const {
+    return (is_na() || rhs.is_na() ||
+            (static_cast<uint64_t>(rhs.value_) >= 64)) ?
+           na() : Int(value_ >> rhs.value_);
+  }
+  constexpr Int logical_right_shift(Int rhs) const {
+    return (is_na() || rhs.is_na() ||
+            (static_cast<uint64_t>(rhs.value_) >= 64)) ?
+           na() : Int(static_cast<uint64_t>(value_) >> rhs.value_);
+  }
+
   // -- Arithmetic operators --
 
   // NOTE: C++11 does not allow `if` in constexpr function, but C++14 does.
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index