hypsakata commented on code in PR #48699:
URL: https://github.com/apache/arrow/pull/48699#discussion_r2656149061
##########
ruby/red-arrow/lib/arrow/array-builder.rb:
##########
@@ -186,6 +199,34 @@ def create_builder(builder_info)
data_type = Decimal256DataType.new(builder_info[:precision],
builder_info[:scale])
Decimal256ArrayBuilder.new(data_type)
+ when :int
+ required_bit_length = builder_info[:bit_length] + 1
Review Comment:
It is because Ruby's `.bit_length` method returns the number of bits
required to represent the integer **excluding the sign bit**.
For example, `GLib::MAXINT16` (32767) is the upper bound of `Int16`, but its
`.bit_length` is 15, not 16.
```ruby
irb> GLib::MAXINT16.bit_length
=> 15
```
Although I could have adjusted the thresholds in the `if` conditions (e.g.,
using 15 for `Int16`), I decided to keep the `builder_info[:bit_length] + 1`.
This aligns the value with standard integer type widths, which I believe makes
the code more intuitive.
If necessary, I can add a comment (e.g., `# Add 1 for the sign bit`) to
clarify this further.
--
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]