apache / arrow

Apache Arrow is the universal columnar format and multi-language toolbox for fast data interchange and in-memory analytics
https://arrow.apache.org/
Apache License 2.0
14.57k stars 3.54k forks source link

[C++] DecimalRealConversion could multiply by 5 instead of 10 #44161

Open bkietz opened 1 month ago

bkietz commented 1 month ago

Describe the enhancement requested

To construct the decimal corresponding to a floating point value, we need to perform the multiplication and division mant * 2^k * 10^scale (k < 0). When performing those operations directly would result in overflow, they are broken into smaller steps of interleaved multiplication and division.

Multiplication by 10 then division by 2 can be losslessly simplified to multiplication by 5. Taking advantage of this should increase perfomance by reducing the number of interleaved steps as well as widening the range across which we can use the faster single step approach. Rewriting the above expression as mant * 5^scale * 2^(k + scale), we can use two cases:

Component(s)

C++

bkietz commented 1 month ago

@pitrou what do you think?

pitrou commented 1 month ago

That's a rather interesting idea. You'll have to make sure there are enough tests to exercise all three cases thoroughly.