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


##########
cpp/src/arrow/compute/kernels/scalar_cast_test.cc:
##########
@@ -1726,6 +1726,45 @@ TEST(Cast, Decimal128ToDecimal32) {
   }
 }
 
+// GH-53288: narrowing to Decimal32 must rescale and range-check the full-width

Review Comment:
   Please augment Decimal128ToDecimal32 instead



##########
cpp/src/arrow/compute/kernels/scalar_cast_numeric.cc:
##########
@@ -486,8 +486,12 @@ struct DecimalConversions<Decimal256, InDecimal> {
 
 template <typename InDecimal>
 struct DecimalConversions<Decimal32, InDecimal> {
-  static Decimal32 ConvertInput(InDecimal&& val) { return 
Decimal32(val.low_bits()); }
-  static Decimal32 ConvertOutput(Decimal32&& val) { return val; }
+  // Scale then truncate. Narrowing in ConvertInput would drop coefficient bits
+  // before Rescale and FitsInPrecision could see them.

Review Comment:
   No need to expand on this.
   ```suggestion
     // Scale then truncate.
   ```



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