zeroshade commented on a change in pull request #10116:
URL: https://github.com/apache/arrow/pull/10116#discussion_r619315524
##########
File path: go/arrow/decimal128/decimal128.go
##########
@@ -54,6 +59,36 @@ func FromI64(v int64) Num {
}
}
+func fromBigIntPositive(v *big.Int) Num {
+ var buf [16]byte
+ // bigint will zero pad the bytes and write them as bigendian
+ // which we can then read out the high and low bytes to construct
+ // our 128bit value.
+ v.FillBytes(buf[:])
+ return Num{
+ lo: binary.BigEndian.Uint64(buf[8:]),
+ hi: int64(binary.BigEndian.Uint64(buf[:8])),
+ }
+}
+
+func FromBigInt(v *big.Int) Num {
+ if v.Sign() < 0 {
+ // if the value is negative, then get the high and low bytes
from the
Review comment:
updated with more clear comments, but essentially: big.Int stores the
value as a boolean for the sign + absolute value, arrow decimal128 expects high
and low bytes as 2's compliment values. So in order to have the correct value
we need to take the bytes (absolute value) and then negate via 2's compliment
if it was negative.
--
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:
[email protected]