spenczar commented on issue #35620:
URL: https://github.com/apache/arrow/issues/35620#issuecomment-1550029592

   `6340900000` is much larger than a 32-bit floating point value can represent 
exactly. A 32-bit `float` value has 23 bits of mantissa so you can only 
represent exact integers up to 2**23 == 8,388,608. 
   
   If you want exact arithmetic at your scale, use the 64-bit `double` type:
   
   ```py
   def test_minimal_viable():
       import pyarrow as pa
       import pyarrow.compute as pc
       first = pa.chunked_array(pa.array([63409]))
       last  = pa.chunked_array(pa.array([35299]))
       intsum = pc.add(
           pc.multiply(first.cast('int32'), pa.scalar(100000)), 
last.cast('int32')
       )
       floatsum = pc.add(
           pc.multiply(first.cast('double'), pa.scalar(100000)), 
last.cast('double')
       )
       raise Exception(f"""PyArrow Float Addition Error
       I am attempting to add {pc.multiply(first,100000)} and {last}.
       When I convert them to integer they yield: {intsum}
       When I convert them to double they yield: {floatsum}
       """)
    ```
   
   yields
   
   ```sh
   I am attempting to add [
     [
       6340900000
     ]
   ] and [
     [
       35299
     ]
   ].
       When I convert them to integer they yield: [
     [
       6340935299
     ]
   ]
       When I convert them to double they yield: [
     [
       6340935299
     ]
   ]
   ```
   
   


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