[ 
https://issues.apache.org/jira/browse/AVRO-4125?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17937372#comment-17937372
 ] 

Martin Tzvetanov Grigorov commented on AVRO-4125:
-------------------------------------------------

Looks like a duplicate of AVRO-4110

> Cast issue when adding Double to DoubleArray in 1.12.0
> ------------------------------------------------------
>
>                 Key: AVRO-4125
>                 URL: https://issues.apache.org/jira/browse/AVRO-4125
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>            Reporter: Adrien Sanchez
>            Priority: Major
>         Attachments: image-2025-03-21-11-43-13-178.png
>
>
> Hi,
> I recently upgraded to Avro 1.12.0, and I have an issue with Double objects 
> when adding them to an array.
> I have an Avro schema in which I have a field that represents geospatial 
> coordinates :
> {code:java}
> {
>   "name": "coordinates",
>   "type": [
>     "null",
>     {
>       "type": "array",
>       "items": {
>         "type": "array",
>         "items": {
>           "type": "array",
>           "items": "double"
>         }
>       }
>     }
>   ],
>   "default": null
> }{code}
> This was well handled in Avro 1.11.4. However, when migrating to Avro 1.12.0, 
> the double items in my array came with some unexpected extra digits.
> Digging into the problem, it looks like the array is handled in 1.12.0 as a 
> *DoubleArray* from the *PrimitivesArrays* class.
>  
> In this class, the add method is implemented this way :
> {code:java}
> public void add(int location, Double o) {
>     if (o != null) {
>         this.add(location, (double)o.floatValue());
>     }
> }
> {code}
> The cast to double primitive type from the float value comes with modifying 
> the precision.
>  
> Here is an example of how the precision is modified in 
> PrimitivesArrays.DoubleArray :
> !image-2025-03-21-11-43-13-178.png|width=446,height=360!
> Here, I expect to add "2.64" to my array, but "2.640000104904175" is actually 
> added in the end.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to