pitrou commented on code in PR #43957:
URL: https://github.com/apache/arrow/pull/43957#discussion_r1763394823


##########
cpp/src/arrow/util/decimal.cc:
##########
@@ -742,6 +1106,78 @@ static inline uint64_t UInt64FromBigEndian(const uint8_t* 
bytes, int32_t length)
   return ::arrow::bit_util::FromBigEndian(result);
 }
 
+Result<Decimal32> Decimal32::FromBigEndian(const uint8_t* bytes, int32_t 
length) {
+  static constexpr int32_t kMinDecimalBytes = 1;
+  static constexpr int32_t kMaxDecimalBytes = 4;
+
+  if (ARROW_PREDICT_FALSE(length < kMinDecimalBytes || length > 
kMaxDecimalBytes)) {
+    return Status::Invalid("Length of byte array passed to 
Decimal32::FromBigEndian was ",
+                           length, ", but must be between ", kMinDecimalBytes, 
" and ",
+                           kMaxDecimalBytes);
+  }
+
+  const bool is_negative = static_cast<int8_t>(bytes[0]) < 0;
+
+  uint32_t result = 0;

Review Comment:
   How about something like:
   ```suggestion
     int32_t result = is_negative ? 0xffffffff : 0;
   ```
   which should automically get you the required sign extension?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to