You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/12/20 06:23:49 UTC

[GitHub] [arrow] kiszk commented on a change in pull request #8955: ARROW-9948: [C++] in Decimal128::FromString raise when scale is out of bounds

kiszk commented on a change in pull request #8955:
URL: https://github.com/apache/arrow/pull/8955#discussion_r546328882



##########
File path: cpp/src/arrow/util/basic_decimal.cc
##########
@@ -949,33 +949,31 @@ DecimalStatus BasicDecimal128::Rescale(int32_t original_scale, int32_t new_scale
 
 void BasicDecimal128::GetWholeAndFraction(int scale, BasicDecimal128* whole,
                                           BasicDecimal128* fraction) const {
-  DCHECK_GE(scale, 0);
-  DCHECK_LE(scale, 38);
+  DCHECK_EQ(ValidateScale(scale), true);
 
   BasicDecimal128 multiplier(ScaleMultipliers[scale]);
   auto s = Divide(multiplier, whole, fraction);
   DCHECK_EQ(s, DecimalStatus::kSuccess);
 }
 
+bool BasicDecimal128::ValidateScale(int32_t scale) { return (std::abs(scale) <= 38); }

Review comment:
       This function can accept `-38 <= scale <= 38` while the original code accepted `0 <= scale <= 38`.   
   Is this change expected? If so, it would be good to leave a comment.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org