gruuya commented on PR #8700:
URL: https://github.com/apache/arrow-rs/pull/8700#issuecomment-3696873750

   > The current implementation has an overflow issue. You can test with the 
following code:
   > 
   > ```
   > let result = 
parse_decimal::<Decimal128Type>("20000000000000000000000000000000000002", 38, 
0).unwrap();
   > assert_eq!(result, 20000000000000000000000000000000000002i128);
   > let result = 
parse_decimal::<Decimal128Type>("20000000000000000000000000000000000002.0", 38, 
0).unwrap();
   > assert_eq!(result, 20000000000000000000000000000000000002i128);
   > ```
   > 
   > The first assert will pass. The second assert will fail:
   > 
   > ```
   > assertion `left == right` failed
   >   left: -14028236692093846346337460743176821143
   >  right: 20000000000000000000000000000000000002
   > ```
   > 
   > There is apparently an interger overflow.
   
   Great catch, thanks!
   
   I revised the implementation a bit, and tried a drive-by `parse_e_notation` 
simplification. We won't hit the integer overflow in this case anymore (added a 
test for it too), since we now avoid the redundant `result = 
result.mul_wrapping(base)` unless we hit an e-notation (in which case we need 
to do it since we don;t know ahead of time what are the actual non-fractional 
digits then).


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