Amogh Margoor created IMPALA-10654:
--------------------------------------

             Summary: Improve the precision of DecimalValue<T>::ToDouble
                 Key: IMPALA-10654
                 URL: https://issues.apache.org/jira/browse/IMPALA-10654
             Project: IMPALA
          Issue Type: Sub-task
            Reporter: Amogh Margoor
            Assignee: Amogh Margoor


>From discussion of IMPALA-10350, it was noted that 
>[DecimalValue<T>::ToDouble|https://github.com/apache/impala/blob/b28da054f3595bb92873433211438306fc22fbc7/be/src/runtime/decimal-value.inline.h#L725]
> is not accurate.

Current approach is: 
{code:java}
 static_cast<double>(value_) / pow(10.0, scale).
{code}

Inaccuracy is due to fact that only integers from −2^53 to 2^53 can be 
represented accurately by double precision without any loss. Hence, above 
approach would not work for numbers like -0.43149576573887316. For DecimalValue 
representing -0.43149576573887316, value_ would be -43149576573887316 and scale 
would be 17. As value_ < -2^53, result would not be accurate. 

Hence through discussion in IMPALA-10350, we propose to use thirdparty library 
https://github.com/lemire/fast_double_parser, which handles above scenario in a 
performant manner. Library's internal representation of Decimal is similar to 
the Impala's DecimalValue and function 
[compute_float_64|https://github.com/lemire/fast_double_parser/blob/e4f6319bfa9cbc829f7f99ae88c1d2fb205c15e8/include/fast_double_parser.h#L232]
 can be used for the conversion.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to