-
Notifications
You must be signed in to change notification settings - Fork 78
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
fix(wallet): fixed precision loss for balance amount #14406
Conversation
Jenkins BuildsClick to see older builds (4)
|
ddd6b45
to
d4dc062
Compare
return self.amount | ||
QtProperty[float] amount: | ||
read = getAmountFloat | ||
QtProperty[float64] amount: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, there are CPUs that do not support float64
so I wonder whether we're not breaking something here. This is also the reason why Qt introduces the qreal
(or real
in QML) type which is an alias for either double
or float
based on what the CPU supports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caybro I have updated nimqml PR after discussion with @alexjba - we lost precision when converted float64 to cfloat. So initially I fixed only this case - when using float64 as property type - I mapped it to double, now as NIM uses float64 for float, we map all float to double. If you want to use 32 float as property type, you should use float32 Please have a look there status-im/nimqml#57
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, we should always use big integers for exchanging balances between go/nim/qml. Using floating points, no matter if 32 or 64 bits it always creates a room for distortions. Some time ago I provided some examples here: #11376. The idea is to always pass integers (big integers) and multiplier specific to given token, like 18 for ETH. Then it gives full freedom on UI side to display or use this balance for other operations like comparisons or multiplications (as in airdrop flow), with no risk of introducing distortions.
fixed currency amount property type to be handled by QMetatype properly
d4dc062
to
1fd0130
Compare
Agree, thank you! Though now it should be twice better since we found what caused big distortions. Since we have a different task for CurrencyAmount as big int, I believe this is out of scope of this fix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say LGTM
and let's handle the issue as a whole in another PR
What does the PR do
Fixes precision loss for big balances.
Related nimqml PR: status-im/nimqml#57 (will be added here once merged)
Affected areas
Wallet->assets balances
Closes #14402