Cast: should get the round result for decimal to a decimal with smaller scale#3139
Conversation
949c6fd to
fbc307d
Compare
tustvold
left a comment
There was a problem hiding this comment.
I think this should consistently use wrapping or checked add, neg, div, rem, etc... This not only is consistent with other kernels, but avoids differences between release and debug builds
There was a problem hiding this comment.
| let d = v / div; | |
| let r = v % div; | |
| let d = v.wrapping_div(div); | |
| let r = v.wrapping_rem(div); |
There was a problem hiding this comment.
| d + 1 | |
| d.wrapping_add(1) |
There was a problem hiding this comment.
| d - 1 | |
| d.wrapping_sub(1) |
There was a problem hiding this comment.
| let neg_half = half.neg(); | |
| let neg_half = half.wrapping_neg(); |
As we've divided by 2 this can't overflow
There was a problem hiding this comment.
| // TODO: it's better to implement the neg | |
| let neg_half = half * i256::from_i128(-1); | |
| let neg_half = half.wrapping_neg(); |
The changes i have done will not overflow. |
|
Do you intend to switch to explicitly using wrapping / checked operations to ensure consistent behaviour across debug and release, and to be consistent with the other kernels? |
fbc307d to
153781d
Compare
Sorry for the late reply, i forgot to push the changes. |
tustvold
left a comment
There was a problem hiding this comment.
I think there is a logical conflict with one of the tests for negative scales
|
Benchmark runs are scheduled for baseline = 2c86895 and contender = 187bf61. 187bf61 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
|
Maybe I got your thought from this commit 2abbf89 But i need time to get the behavior of negative scale when we do cast in other system. |
|
123 |
I am confused about this, if the data type is decimal(10,-2) and the 128-bit integer is I think the 128-bit integer should be From the doc: https://arrow.apache.org/docs/python/generated/pyarrow.decimal128.html#pyarrow-decimal128 |
|
Apologies I misread your example, if the integer value was |
Which issue does this PR close?
Closes #3137
Rationale for this change
What changes are included in this PR?
Are there any user-facing changes?