-
Notifications
You must be signed in to change notification settings - Fork 344
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
math: support power operation with two real numbers (std::Decimal) #1857
Comments
Which operation exactly do you need? |
I would not recommend doing that kind of math with cosmwasm_std::Decimal or cosmwasm_std::Decimal256 because they are both fixed point decimals. This means especially multiplications and powers can quickly lead to significant rounding errors. I'd look for a library specific for that kind of job and have a layer of converting inputs and outputs. Real numbers could be implemented with either floats or floating point decimals. Floats are currently disabled, but might be shipped as part of the next release if everything goes well: #1845. If that works out you can use native f32/f64. Floating point decimals are like Decimal but the dot is moving instead of being always 18 positions left of the end. This allows very high values or very low values with much lower loss of precision. Some examples for that approach are:
|
I'm using this library to solve this problem, but it's not fit with the big numbers from Osmosis' weighted pool. I think it does not solve the issue that i surfaced even if cosmwasm supports f32/f64.
I'm totally agree with your opinion and this should not be applied on this library for same reason. I found Osmosis team uses Taylor Expansion + big.Int to approximate pow operation. So there's two point to choose if i really want to use pow operation.
|
What's a typical value range for those t, B and W? Maybe the 18 digit fixed point is good enough? |
I'll let you know if i check the actual value of it |
Not planned for now. |
Is there any plans to support power operation between two Decimals? I'm currently developing the pool swap simulator on Osmosis, but there's some limitation of implementing "math stuffs" like pow operation.
The text was updated successfully, but these errors were encountered: