-
Notifications
You must be signed in to change notification settings - Fork 916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEA] Improve accuracy when casting floating-point numbers to decimal #11079
Comments
Why? float -> integer rounding in C++ always rounds towards zero. |
That is rounding. We are casting instead, rounding is just the way we use to do casting. |
Oh here we are casting from floating-point to fixed-point, thus the casting to use should be float-to-point rounding then casting to int, not float-to-int direct casting. float-to-float rounding is round-to-nearest by C++ specs. |
(reposting this message from slack) There is a long history behind this and truncation is definitely the desired and intentional behaviour. Here are the main motivations for truncation:
Note that at one point, we actually did have rounding functionality baked into floating point construction for fixed-point. However, it wasn't actually to address the desire to be more "accurate" as @ttnghia is pointing out, it was to try and address inherent issues in floating point (such as |
Thanks @codereport. That explains to me why we have such choice and I'm convinced with it. So I'm going to close the issue. |
Currently, decimals constructed from floating-point numbers are done by:
scale
value)Ref:
cudf/cpp/include/cudf/fixed_point/fixed_point.hpp
Line 230 in fae2221
As such, a number like
0.28
andscale=-1
can be shifted and rounded to2
and stored as2
! Of course the more accurate rounded number should be3
. We should do a better rounding for this process.Such rounding was causing issues for the users. In particular, in spark-rapids: NVIDIA/spark-rapids#5765
The text was updated successfully, but these errors were encountered: